EDIT: Here's an updated version; the previous one treats tracks that haven't been added to the library as though they have when they're opened from the library tab. Also there's no tick anymore for 'added and downloaded' because it seemed superfluous. https://share.folivora.ai/sharedPreset/26bd207c-e1a3-4619-91ba-a445ab5c242d
add to library:
download:
added and downloaded:
(now playing widget not included in the preset, it's just the default one included in BTT)
Really handy, really nice preset! I just have the little problem that I won't get the arrow (last screenshot) once I downloaded the song to my library The widget just disappears
sorry here's a third version that's fixed another problem with it -- some track properties in iTunes keep changing depending on where you're playing them from so it's tricky to detect whether it's been added to library etc.
yeah I removed that after the first version because it seemed superfluous -- I couldn't figure out how to get iTunes to remove tracks from the library so I couldn't add a function to tick button. Feel free to add it back in; you just have to copy and paste the icon data from for the tick from the first version.
I'm still a bit new to Apple script.
Could someone explain me how to include my own image into a return? If I have a png file how can I display it? How can I find the text to enter into my script?
Thank you guys
Sweet! Will update the one I'm using in my local dev version
EDIT: I can verify that this version has killed off all remaining bugs and functions correctly!!!
EDIT2: Might've spoken too soon, the download button shows up for certain songs even if it's already downloaded o_O weird. I'll troubleshoot it a bit later.
Turns out this widget is what's causing the iTunes launching bug - whenever iTunes is currently playing music and the user quits the app, if this widget is active iTunes will automatically relaunch.
I can't figure out why this is happening. @Andreas_Hegenberg do you have any idea how to fix this? I've looked over the script again and again and I don't see anything wrong.
hey, I'm not sure why it's happening either, but I've not been having problems with it mainly because I have it in a conditional activation group that only becomes visible when iTunes is the currently playing app -- setting it up that way (or setting it such that it's only visible when the iTunes process is running) could be a way around this.
EDIT: turns out using 'tell application' always launches the application (source). Likewise, using if application "iTunes" is running also itself launches iTunes.
One way around this is to wrap the whole applescript inside something like tell application "System Events" / if application process "iTunes" exists then... but that seems to take a long time to run because it essentially checks the name of every process currently running. I think using conditional activation groups basically achieves the same thing without lag.
Aha, I fixed it! I was able to stop iTunes from relaunching by wrapping the entire inner contents of the script in a try statement.
if application "iTunes" is running then
tell application "iTunes"
try
set trackName to name of current track
set libraryCheck to tracks in playlist "Music" whose name is trackName
set playlistClass to class of current playlist
try
set trackClass to class of item 1 of libraryCheck
end try
if libraryCheck is {} or trackClass is URL track then
return "add to library"
else if libraryCheck is {} and playlistClass is not user playlist then
return "add to library"
else
try
get location of item 1 of libraryCheck
return ""
on error
return "download"
end try
end if
on error
return ""
end try
end tell
else
return ""
end if