get path to [shared] itunes track

is there a way to get the path to a selected track in a shared playlist in itunes.

thanks.

No, there’s no location property of shared track
Apple doesn’t want and doesn’t support to copy music over a shared library.

But you can access the computer, which shares the library, e.g. with Remote Apple Events and get the location

how would i do that?

For example:

-- Remote Apple Events must be enabled on remote machine

property user_name : "user"
property pass_word : "pass"
property UserID : "501"

set RemoteServer to choose URL showing File servers -- get remote server
set RemoteBonjourName to characters 7 thru -2 of RemoteServer as string -- set remote server bonjour name
set RemoteMachine to "eppc://" & user_name & ":" & pass_word & "@" & RemoteBonjourName & "/?uid=" & UserID

tell application "Finder" of machine RemoteMachine
	using terms from application "Finder"
		if "iTunes" is not in (get name of processes) then open application file id "com.apple.iTunes"
		repeat until "iTunes" is in (get name of every process)
			delay 1
		end repeat
	end using terms from
end tell

display dialog "Select one shared track and resume script"

tell application "iTunes"
	set sel to item 1 of (get selection)
	if class of sel is shared track then
		set {album:Al, artist:Ar, date added:Da, name:Na} to sel
	else
		display dialog "This isn't a shared track" buttons {"Cancel"} default button 1
	end if
end tell

tell application "iTunes" of machine RemoteMachine
	using terms from application "iTunes"
		set Loc to location of 1st track of playlist "Library" whose album is Al and artist is Ar and date added is Da and name is Na
	end using terms from
end tell

how would i do this if i had more that 1 track in the selection? all i need is the last 2 tell blocks.

thanks.

EDIT: also i’v been trying for hours, how do i copy the song to the local itunes library.

this works for more than on track
the result is a list of POSIX paths in locationList.
To copy the files, mount the volume, calculate the absolute paths and copy the files.
Note: the path of an admin user on a remote machine starts with /Users/username, a standard user with /username

-- Remote Apple Events must be enabled on remote machine

property user_name : "user"
property pass_word : "pass"
property UserID : "501"
global RemoteMachine

set RemoteServer to choose URL showing File servers -- get remote server
set RemoteBonjourName to characters 7 thru -2 of RemoteServer as string -- set remote server bonjour name
set RemoteMachine to "eppc://" & user_name & ":" & pass_word & "@" & RemoteBonjourName & "/?uid=" & UserID

tell application "Finder" of machine RemoteMachine
	using terms from application "Finder"
		if "iTunes" is not in (get name of processes) then open application file id "com.apple.iTunes"
		repeat until "iTunes" is in (get name of every process)
			delay 1
		end repeat
	end using terms from
end tell

repeat
	display dialog "Select one or more shared tracks and resume script"
	tell application "iTunes" to selection is {}
	if result is false then exit repeat
end repeat

set locationList to {}
tell application "iTunes"
	repeat with oneTrack in (get selection)
		if class of oneTrack is shared track then
			set end of locationList to my get_Location(oneTrack)
		end if
	end repeat
end tell

on get_Location(Tr)
	tell application "iTunes" to set {album:Al, artist:Ar, date added:Da, name:Na} to Tr
	tell application "iTunes" of machine RemoteMachine
		using terms from application "iTunes"
			return (location of 1st track of playlist "Library" whose album is Al and artist is Ar and date added is Da and name is Na) as Unicode text
		end using terms from
	end tell
end get_Location

ok, i got the volume to mount, but how do i get the path of the volume, cuz my hd and the remote hd are both named macintosh hd.

Then I would use the shell.
Your startup volume starts: with /Users/
The remote machine with: /Volumes/Macintosh HD/Users/

and don’t forget to quote the paths :wink:

repeat with a in locationList
	do shell script "cp '/Volumes/" & theVolume & a & "' ~/"
end repeat

thats what i have theVolume is the name of the volume and i get this error

sh: -c: line 1: unexpected EOF while looking for matching `‘’
sh: -c: line 2: syntax error: unexpected end of file

Is there a slash between theVolume and a?
btw: Quotation for ~/ is not necessary, because there is no space character in it

yeah i returned that whole line and the path looks fine and there is no quotation around it thats the ending for the first part. when you type it into terminal it doesnt work either.

I tried it on my machine and it works with this code (the remote user has admin status!)

repeat with a in locationList
	do shell script "cp " & quoted form of POSIX path of a & " ~/"
end repeat

ok, i figured out the copying part, but i looked in my volumes folder and saw my local hd (macintosh hd) and the mounted remote macintosh hd-1 so how do i use applescript to get the name of the remote hard drive? because they are both named the same thing.

I can’t try this, because I don’t want to rename my volumes, but does the mount volume command return the right name ?

set myDisk to (mount volume “afp://user:pass@myServer.local/myVolume”) as alias

nope that just returned macintosh hd.

next try

set myDisk to POSIX path of (mount volume "afp://user:pass@myServer.local/myVolume")

yup thats works, thanks.

one more thing, how would i eject the volume

i’ve tried this

tell application "Finder" to eject disk "Macintosh HD-1"

and a bunch of variations (/Volumes/Macintosh HD-1)

do shell script "diskutil unmount /Volumes/Macintosh\ HD-1"

that returns this

"Disk Utility Tool Usage: diskutil [mount(Disk)|unmount(Disk)|eject] <force> [Mount Point|Disk Identifier|Device Node] Mount, unmount or eject local disks or volumes. force is only valid on unmount or unmountDisk. Example: diskutil unmount /Volumes/SomeDisk"