Add to library (and download) button for iTunes

This is a preset for adding and downloading Apple Music tracks to your iTunes library: https://share.folivora.ai/sharedPreset/a1c03ee1-9554-438a-a3f4-7795b8e644c4

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:
01%20pm

download:
06%20pm

added and downloaded:
27%20pm

(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 :confused: The widget just disappears :hushed:

This seems VASTLY superior to my version! I will definitely replace the one I'm using with a version of this :slight_smile:

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.

https://share.folivora.ai/sharedPreset/4445cd13-3971-4c48-a0d2-e883029c1b32

this should be the last one! should have used this for longer to look for problems before uploading in the first place

2 Likes

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.

1 Like

Got it! Works perfectly!
Do you mind if I add it to my Caliguvara C Preset?

Me to for AquaTouch!
Full credit within code and on the changelog. XD you know you've made something good when we all want it :stuck_out_tongue:

1 Like

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 :slightly_smiling_face:

here's um a fourth version that fixes a few more problems with identifying the status of a track: https://share.folivora.ai/sharedPreset/9e37c748-736f-45c6-a2f1-8aeb94a04126
I've used this for a few days without issue now so, fingers crossed, this one covers all the bases?

Feel free to use this wherever!

1 Like

convert the image into a base64 string here: https://www.base64-image.de
and then follow instructions here: https://github.com/folivoraAI/BetterTouchTool/issues/2038

1 Like

Sweet! Will update the one I'm using in my local dev version :slight_smile:

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
2 Likes