Skip to content

Instantly share code, notes, and snippets.

@detecti1
Created August 10, 2023 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detecti1/f7d04129ef9e2b5d4987a9dfcadbdec1 to your computer and use it in GitHub Desktop.
Save detecti1/f7d04129ef9e2b5d4987a9dfcadbdec1 to your computer and use it in GitHub Desktop.
Set Loved and add apple music track to library via applescript
tell application "Music"
set loved of current track to true
set songTitle to name of current track
set songAlbum to album of current track
set songInfo to songTitle & " - " & songAlbum
try
duplicate current track to source 1
on error
try
tell application "System Events"
tell its process "Music"
try
click menu item "添加到资料库" of menu "歌曲" of menu bar 1
on error
keystroke "m" using {command down, shift down}
delay 1
click menu item "添加到资料库" of menu "歌曲" of menu bar 1
keystroke "m" using {command down, shift down}
end try
end tell
end tell
on error errorMsg number errorNum
display notification "Failed to add to library: " & songInfo & errorMsg
error errorMsg number errorNum
end try
end try
display notification "Loved song: " & songInfo
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment