Skip to content

Instantly share code, notes, and snippets.

@scottj
Last active April 17, 2024 21:55
Show Gist options
  • Save scottj/bcd2cb7b34f230e51c71d5fbf53c6066 to your computer and use it in GitHub Desktop.
Save scottj/bcd2cb7b34f230e51c71d5fbf53c6066 to your computer and use it in GitHub Desktop.
Search Music.app on macOS
#!/bin/bash
QUERY=$1
# https://stackoverflow.com/a/246128/226502
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
/usr/bin/osascript ${SCRIPT_DIR}/music-search.scpt "${QUERY}"
on run argv
set savedClipboard to the clipboard
set the clipboard to ({item 1 of argv} as text)
do shell script "open /System/Applications/Music.app"
tell application "Music" to activate
delay 1.25
tell application "System Events"
keystroke "f" using command down
keystroke "a" using command down
keystroke "v" using command down
delay 2
key code 36
end tell
delay 2
set the clipboard to savedClipboard
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment