Is there a way to be able to access the same function that the F7, F8 and F9 keys on the Apple Keyboard have in Swift for Mac OS X as I want to be able to create a button that will either pause the current playing track in Spotify or iTunes and then play it again.
Asked
Active
Viewed 774 times
1 Answers
0
You can use Applescript to do this, running the applescript from swift with NSAppleScript
. Here's a quick and dirty example for toggling the play/pause state of the current track in spotify:
let command = "if application \"Spotify\" is running then tell application \"Spotify\" to playpause"
let commandObject = NSAppleScript(source: command)
var error: NSDictionary?
commandObject!.executeAndReturnError(&error)
You can read more information about Spotify's applescript API at https://developer.spotify.com/applescript-api/