Hello all. I’ve got a simple script here but can’t figure out why it works perfect in AppleScript Editor, but not in my AppleScriptObjC application. The error I get in Xcode when running this is “Can’t find remote machine (error -915).”
Of note I have declared the variable theRemoteMac in AppDelegate.applescript like this:
property theRemoteMac : missing value
Also, I should say that if I replace theRemoteMac with actual address/URL, everything works fine in Xcode. See below…
This does not work in Xcode:
set theRemoteMac to "eppc://username:password@server.local"
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteMac
play
end tell
end using terms from
This does work in Xcode:
using terms from application "iTunes"
tell application "iTunes" of machine "eppc://username:password@server.local"
play
end tell
end using terms from
Well, logging the variable didn’t really do much besides confirm that the variable was correctly set earlier in the script. Thanks for the suggestion though!
After trying what felt like a hundred different ways of setting the variable (as string, as unicode text, quoted form of, etc.) and wrapping the “eppc://” and it’s variables in various configurations of parentheses, I have finally found something which works. Check it out below, and if anyone knows why this works, I would love to hear the explanation!
on buttonClicked_(sender) -- LINKED TO BUTTON IN IB
set theUserName to "username" -- YOUR USER NAME
set thePassword to "password" -- YOUR PASSWORD
set theHostName to "iMac.local" -- YOUR REMOTE MAC'S HOST NAME
-- DON'T REALLY UNDERSTAND WHY THIS NEXT LINE WORKS, BUT IT DOES (PART 1):
set theApp to "eppc://" & theUserName & ":" & thePassword & "@" & theHostName & "/iTunes"
-- SEEMS AS THOUGH ALL EPPC COMMANDS/CONNECTIONS IN APPLESCRIPTOBJC MUST BE WRAPPED IN "USING TERMS FROM" BLOCKS:
using terms from application "iTunes"
-- DON'T REALLY UNDERSTAND WHY THIS NEXT LINE WORKS, BUT IT DOES (PART 2):
tell application theApp
-- GETTING THE SONG NAME AND ARTIST OF THE CURRENTLY PLAYING TRACK:
set theCurrentTrack to (name of current track) as text
set theArtist to (get artist of current track) as text
end tell
end using terms from
-- DISPLAYING THE SONG NAME AND ARTIST OF THE CURRENTLY PLAYING TRACK:
tell me to activate
display dialog theCurrentTrack & " by " & theArtist
end buttonClicked_
Ops! Sorry, the thingie that works here, actually is:
set machina to s & u & machin of myTunes
end if
try
with timeout of 30 seconds
try
using terms from application "Finder"
tell application "Finder" of machine machina
process "iTunes"
end tell
end using terms from
-- try to connect first to an app that does not close.
So the variable is also built from bits. I think, maybe for similar reasons, it didn’t work…
– try to connect first to an app that does not close.
I remember this bit was because if I had a previous connection to iTunes that meanwhile closed and reopened, or the script was recompiled, the script would fail, miserably…