Last active
April 24, 2019 06:04
-
-
Save what-name/1258305d5fa292d9be126a0ffa8137dd to your computer and use it in GitHub Desktop.
An Applescript application that connects to a bluetooth speaker->starts iTunes->starts playing a playlist automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- works as of MacOS Mojave, iTunes 12 | |
-- TIMESTAMP: 24. Apr. 2019 | |
-- clear start - quit itunes | |
tell application "iTunes" | |
quit | |
end tell | |
delay 60 -- sometimes iTunes takes a while to quit | |
-- turn on bluetooth if off | |
tell application "System Preferences" | |
quit | |
delay 1 | |
activate | |
set the current pane to pane id "com.apple.preferences.Bluetooth" | |
delay 2 -- pane switching in System Prefs is painfully slow for some reason | |
tell application "System Events" | |
tell process "System Preferences" | |
tell window "Bluetooth" | |
tell button 3 | |
if name is "Turn Bluetooth On" then click | |
end tell | |
end tell | |
end tell | |
end tell | |
quit | |
end tell | |
delay 3 -- safety net | |
-- connect to Bluetooth speaker | |
activate application "SystemUIServer" | |
tell application "System Events" | |
tell process "SystemUIServer" | |
-- Working CONNECT Script. Goes through the following: | |
-- Clicks on Bluetooth Menu (OSX Top Menu Bar) | |
-- => Clicks on device Item | |
-- => Clicks on Connect Item | |
set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth") | |
tell btMenu | |
click | |
tell (menu item "bluetoothSpeakerName" of menu 1) | |
click | |
if exists menu item "Connect" of menu 1 then | |
click menu item "Connect" of menu 1 | |
else | |
key code 53 -- Close main BT drop down if Connect wasn't present | |
end if | |
end tell | |
end tell | |
end tell | |
end tell | |
delay 8 -- wait for bluetooth connection before playing | |
set volume output volume 70 | |
tell application "iTunes" | |
activate | |
delay 3 | |
set shuffle enabled to true | |
play playlist "playlistName" | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment