Automate Launching VSCode in Fullscreen using Applescript

by
, posted

You might be familiar with the command to open a directory or file in VSCode. By triggering code . the command launches the current working directory or the file you pass in as an argument in VSCode, which is quite convenient.

alt text

However, by default the window launches as a small display which rquires manual intervention to be maximized or a simple shortcut works Ctrl + CMD + F

For a long time I have been thinking to make the process more frictionless i.e devising a way that simply firing code . in terminal should launch VSCode in fullscreen mode. And I finally got it sorted. Read on to know how.

Workflow : Write an Applescript that executes the aforementioned keyboard shortcut → Write a bash function to append code . with a command to execute applescript along with it whenever code command is fired.

Setup

Save this script as fullscreen.oscp at your desired location. I saved it directly under my home directory /Users/wired/

tell application "Visual Studio Code"
    activate
    delay 0.3
    tell application "System Events"
        keystroke "f" using {control down, command down}
    end tell
end tell

Next, launch your terminal and run which code to determine the actual location of your code executable on your system. Note it as we need it for the upcoming bash function. In my case it is ‘/usr/local/bin/code’.

Now open your default shell config file ‘~/.zshrc’ and add this function inside it:

function code() {
    /usr/local/bin/code "$@" && osascript /Users/wired/fullscreen.scpt
}

Save the file and exit. Restart your terminal or source your shell config file and you are done. To confirm that it is working, try running ‘code .’ inside any of your projects; VSCode should launch in fullscreen mode.

alt text

Well that might not look significant but for a seasoned code editor it represents yet another obstacle successfully overcome. To further streamline your experience with VSCode on Mac, check out this list of Keyboard Shortcuts.


This is Day 19 of #100DaysToOffload

That is all for today. If you found this post useful consider sharing it with friends.

Your Signature