Friday, July 30, 2010

#1 2007-05-22 04:08:24 pm

andemann
Member
Registered: 2006-05-23
Posts: 4

Returning constants to php/OSAScript

I am trying to return the "special kind" property of a iTunes playlist
When running the script in the script editor, it returns "Party Shuffle", when i run
osascript testscript.scpt in terminal, or calls it from php, it returns
«constant ****kSpS»--«constant ****kSpS»

Is there any way that I can get the text value of the constant returned?
I tried to split the characters of the constant into a list and putting them toghether again, but the result was the same

Applescript:


tell application "iTunes"
   set out to ""
   repeat with plist in user playlists
       set out to ((special kind of plist) as text)
       exit repeat
   end repeat
   
   set out to (out as text)
   set out to characters 1 thru (number of characters in out) of out
   --set out to all characters of out
   set out2 to ""
   repeat with ttt in out
       set out2 to out2 & ttt
   end repeat
   return out2
end tell


Filed under: iTunes

Offline

 

#2 2007-05-23 04:57:09 am

regulus6633
Member
From: Hillerød, Denmark
Registered: 2006-11-01
Posts: 1224

Re: Returning constants to php/OSAScript

How about this...

Applescript:

set plist_record to {}
tell application "iTunes"
   set plists to every user playlist
   repeat with a_plist in plists
       set end of plist_record to {plistName:(name of a_plist), specialKind:(special kind of a_plist) as string}
   end repeat
end tell
get plist_record


Filed under: iTunes

Offline

 

#3 2007-05-23 02:02:20 pm

andemann
Member
Registered: 2006-05-23
Posts: 4

Re: Returning constants to php/OSAScript

Jacques:  Tested your solution from the terminal, and it works perfectly.

regulus6633: Have not tested your solution in the actual project, but when testing it using terminal it returned the following info: osascript testscript2.scpt
plistName:Partymiks, specialKind:«constant ****kSpS»,

Thank you both for helping me solv the problem.

Anyone got an answer for the question, how to return the constant string?

Andreas

Offline

 

#4 2007-05-24 08:37:02 am

hhas
Member
Registered: 2004-04-29
Posts: 390

Re: Returning constants to php/OSAScript

andemann wrote:

Is there any way that I can get the text value of the constant returned?

You'll only get a human-readable representation if the AppleScript component has previously loaded the iTunes dictionary, which it only does when compiling scripts.

The simplest thing would be to save your script in uncompiled form (testscript.applescript), so osascript automatically compiles it each time it's run.

Alternatively, you could add a 'run script' command to your script that compiles a simple iTunes script, again forcing AppleScript to load the relevant terminology, e.g.:

Applescript:

run script "tell application \"iTunes\" to get name"

HTH


Learn AppleScript, 3rd edition - Sanderson & Rosenthal (Apress)
appscript - Control scriptable apps from Python, Ruby and ObjC

Offline

 

#5 2007-05-24 02:42:41 pm

andemann
Member
Registered: 2006-05-23
Posts: 4

Re: Returning constants to php/OSAScript

hhas wrote:

The simplest thing would be to save your script in uncompiled form (testscript.applescript), so osascript automatically compiles it each time it's run.

Just saved my file as text  and used the name testcript.applescript and it worked.
I suspect there is a performance cost of doing it like this vs precompiled script, but calling osascript from php causes a delay to start with.

Andreas

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.157 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)