r/applescript • u/maxihash • Nov 08 '24
Simulate Keyboard press for Play/Pause
I want to simulate the keyboard Play/Pause to stop media from playing at a certain time using AppleScript. I think using the key code 100 will not work, as I found someone explaining this here 3 years ago.
My question is, is there an alternative way to do this in 2024? Do we need a 3rd party app? I found that BetterTouchTool is overkill for this, but I haven’t tried it. Can anyone suggest the best method?
2
Upvotes
View all comments
Show parent comment
1
u/malik_ji Nov 10 '24
kindly test this
tell application "System Events" to tell application process "Control Centre"set nowPlaying to first menu bar item of menu bar 1 where description contains "Now Playing"click nowPlayingrepeat until exists (UI element 6 of group 1 of window "Control Centre")delay 0.2end repeatdelay 0.2click UI element 6 of group 1 of window "Control Centre"delay 0.2click nowPlayingend tell