Automator + Applescript how to: new Desktop (open Calendar and Reminders in it)
Asked Answered
M

4

7

The title is what I'm trying to achieve.

In Automator, I've tried to simply record the actions of opening a new desktop, and then opening the apps in it -- but I get the

The action 'Watch Me Do' encountered an error. Check the actionʼs properties and try running the workflow again

Furthermore, if I do it in this way, the action that is recorded is "Click the Desktop 4 button".

Similarly, I googled and found Applescripts that create specific Desktops (e.g. Desktop 3) but I always have a different amount of Desktops open. So I want the Workflow to simply make a new Desktop regardless of the amount I have open already. Moreover, many of the Applescripts I do find are geared towards Mavericks which still had Spaces and I've got Yosemite.

I can figure out how to make the script open Calendar and Reminders, so the main issue is how to have it open or create a new Desktop.

Melany answered 20/3, 2015 at 11:50 Comment(0)
U
11

Took a while but I came up with this. Works on Mavericks.

on run {input, parameters}
    my openNewSpace()
    my launchApplication("Reminders")
    my launchApplication("Calendar")
end run

on openNewSpace()
    tell application "System Events"
        --mission control starten
        do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"
        tell process "Dock"
            set countSpaces to count buttons of list 1 of group 1
            --new space
            click button 1 of group 1
            --switch to new space
            repeat until (count buttons of list 1 of group 1) = (countSpaces + 1)
            end repeat
            click button (countSpaces + 1) of list 1 of group 1
        end tell
    end tell
end openNewSpace

on launchApplication(app_name)
    tell application app_name
        launch
    end tell
end launchApplication
Urticaceous answered 20/3, 2015 at 21:27 Comment(2)
Awww yusss!! This did it perfectly, thank you so much! :) I want to upvote your solution but I don't have enough rep, so I'll come back when I do!Melany
This solution does not seem to work anymore on macOS Sierra :-(Osmen
H
3

Works fine on macOS Mojave (10.14.3)

AppleScript:

tell application "System Events"
    tell application "Mission Control" to launch
    tell group 2 of group 1 of group 1 of process "Dock"
        click (every button whose value of attribute "AXDescription" is "add desktop")
        tell list 1
            set countSpaces to count of buttons
            delay 0.5
            click button (countSpaces)
        end tell
    end tell

    delay 0.5
    tell application "Calendar" to launch
    tell application "Reminders" to launch
end tell

JXA:

Application("Mission Control").launch()

var proc = Application("System Events").processes['Dock']
var group = proc.groups[0].groups[0].groups[1]

var bs = group.buttons.whose({ description: "add desktop"})
Application("System Events").click(bs[0])

delay(0.5)
var li = group.lists[0]
Application("System Events").click(li.buttons[li.buttons.length - 1])

delay(0.5)
Application("Calendar").activate()
Application("Reminders").activate()
Homomorphism answered 19/2, 2019 at 10:11 Comment(1)
I would have +1; however, as currently coded one is not guaranteed to be taken to the Desktop just created. In other words, e.g., if I have 2 Desktops and one app running full screen when the code is run, a third Desktop is indeed created; however, I'm taken to the full screen app, not the third Desktop. Additionally, assuming Calendar and Reminders were closed when run, there are launched on the Desktop that had focus when the code was run, not the Desktop just created. Your code also doesn't take into account what if either Calendar and or Reminders are all ready open when the code it run.Chalmer
B
1

This works on my macOS Mojave 10.14.4

If you using other languages you need to replace "add desktop" to your system language.

AppleScript:

tell application "System Events"
tell application "Mission Control" to launch
tell group 2 of group 1 of group 1 of process "Dock"
    click (every button whose value of attribute "AXDescription" is "添加桌面")
    tell list 1
        set countSpaces to count of buttons
        delay 0.5
        click button (countSpaces)
    end tell
end tell
Bowlds answered 5/4, 2019 at 13:19 Comment(2)
In future please avoid asking questions in your answer. If you have another question, post it as such using the [Ask Question] button in the top right of the page.Protectionist
You obviously just copied the code from Mike Miklin's answer, deleting the last four lines while changing "add desktop" to "添加桌面" and in doing so doesn't really answer the question that was asked! Also in do so, your copied code doesn't compile because your deleted a necessary line, a closing end tell.Chalmer
S
0

macOS Monterey 12:

tell application "System Events"
    --mission control starten
    tell application "Mission Control" to launch
    delay 0.25
    tell process "Dock"
        set countSpaces to count buttons of list 1 of group 2 of group 1 of group 1
        --new space
        click button 1 of group 2 of group 1 of group 1
        --switch to new space
        repeat until (count buttons of list 1 of group 2 of group 1 of group 1) = (countSpaces + 1)
        end repeat
        click button (countSpaces + 1) of list 1 of group 2 of group 1 of group 1
    end tell
    delay 0.25
    tell application "Calendar" to launch
    tell application "Reminders" to launch
end tell
Shuck answered 11/4, 2022 at 6:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.