Sample Header Ad - 728x90

Open a new workspace in OSX without using the mouse

0 votes
1 answer
149 views
I am used to Linux environments but I have to use a Mac for work. Now I am wondering why it seems to be impossible to open new workspaces in OSX without using the mouse. I know how to switch between them or move windows in different workspaces, when they are already open, but there seems no way to open or close a workspace just by keyboard shortcuts. I am already using Amethyst but it seems not to help with this problem. I already tried using an AppleScript, that I found in another thread. But it doesn't work since, Mission Control is not available as an application in the current OSX.
User
tell application "System Events"
    do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"
    tell process "Dock"
        set countDesktops to count buttons of list 1 of group 1
        --new desktop
        click button 1 of group 1
        --switch to new desktop
        repeat until (count buttons of list 1 of group 1) = (countDesktops + 1)
        end repeat
        click button (countDesktops + 1) of list 1 of group 1
    end tell
end tell
I asked ChatGPT to adjust it and this came out:
tell application "System Events"
    -- This would be where you'd simulate opening Mission Control, 
    -- but since we can't directly do "Control + Up Arrow", we might consider other methods 
    -- or manual activation before running the script.
    tell process "Dock"
        set countDesktops to count buttons of list 1 of group 1
        -- Assuming Mission Control is already open, attempt to create a new desktop
        click button 1 of group 1
        delay 1 -- Wait for the animation to complete; adjust delay as necessary
        -- Attempt to switch to the new desktop, assuming it's been created
        set newCountDesktops to count buttons of list 1 of group 1
        if newCountDesktops > countDesktops then
            click button newCountDesktops of list 1 of group 1
        end if
    end tell
end tell
I saved it as an AppleScript in Automator and assigned a hotkey to it. When I now open mission control manually and press my assigned hotkeys, nothing happens. How may I debug this script or otherwise solve the main problem ?
Asked by jo87casi (101 rep)
Feb 25, 2024, 05:20 PM
Last activity: Apr 21, 2025, 06:02 PM