r/applescript • u/Creepy-Share7191 • Nov 18 '24
Should I use AppleScript for this?
When I leave my room, I want my laptop and monitor to shuffle a playlist on Apple Music, Play an MOV video on one screen, and pull up a photo on another from my finder. The problem I am running into is A) I dont know how to get my photo onto the other monitor, and B) Apple Music is often laggy and putting in pre-defined keystrokes sometimes wont do the trick. I feel like using inputted keystrokes is super jank to solve this, but I'm not sure if there is a better way to do it. Should I bu using AppleScript for this project? I am looking for basically 99% success rate. Here is some of my code below:
tell application "Music"
**activate** \-- Brings Apple Music to the foreground
end tell
tell application "System Events"
**delay** 2 -- Wait for Music to become active
**keystroke** "f" using {*command down*} -- Opens the search bar
**keystroke** "f" using {*command down*} -- Opens the search bar
**delay** 1
**keystroke** "Asian lofi" -- Types the search query
**delay** 0.2
**keystroke** return -- Presses Enter to search
**delay** 0.2
**key code** 53 -- Presses Escape to close the search suggestions or dropdown
**delay** 0.2
**key code** 48 -- Presses Tab (once)
**delay** 0.2
**key code** 48 -- Presses Tab (second time)
**delay** 0.2
**keystroke** return -- Presses Enter to open playlist
**delay** 2
**key code** 48 -- Presses Tab
**delay** 2
**key code** 48 -- Presses Tab to navigate to play button
**delay** 1
**key code** 48 -- Presses Tab to navigate to shuffle button
**delay** 0.5
**keystroke** return -- Presses Enter to start
**delay** 0.5
end tell
View all comments
Show parent comment
2
u/Creepy-Share7191 Nov 19 '24
Wow, that worked like a charm, thank you! I'll try to use scripting dictionaries moving forward