I’m struggling with a bit of Applescript reference syntax and I was wondering if someone could point me in the right direction. It’s probably really obvious but I’m having a real brainlock on it.
I have a script that processes a list of references from iView MediaPro. These look like something like this
{id 1850 of window 1, id 1853 of window 1, id 1849 of window 1, id 1854 of window 1, id 42 of window 3}
What I want to do is take each object reference in turn and process the reference to get the target of an object (i.e. in this case, either window 1 or window 3).
So, I’d want something not unlike
repeat with inputObject in input
set inputWindowName to name of window of inputObject
end repeat
But, of course, this doesn’t work.
So this begs the question, how do you take a general Applescript reference (say “x of y”) and process it to get “y”.
I’m sure this is obvious but I’m just not getting enough clues from the syntax to make much progess so any pointers are appreciated.
Ah. Maybe I wasn’t clear. I don’t have any problem getting the items out of the list. However, once I have inputObject in the example I gave, I want to be able to break apart the actual individual references in the list. So, for example, I have the following loop
repeat with inputObject in input
..
..
..
end repeat
and inputObject is equal to this reference on the first iteration
id 1850 of window 1
then what I want I know is what I need to do to inputObject in order to get “window 1” as a result.
Cheers
Scott…
Browser: Safari 412
Operating System: Mac OS X (10.4)
set input to {"id 1850 of window 1", "id 1853 of window 1", "id 1849 of window 1", "id 1854 of window 1", "id 42 of window 3"}
repeat with inputObject in input
set ASTID to AppleScript's text item delimiters--Store default text separator
set AppleScript's text item delimiters to "of"--Identifies separations of text per item as the characters "of"; this is called "parsing"
set theWindow to display dialog text item 2 of inputObject as text--gets item 2 of inputObject, now defined as window 1. "Display dialog" is there for your visual confirmation and should be removed.
set AppleScript's text item delimiters to ASTID--Returns default "text delimiter"
end repeat
The script wouldn’t compile without “” for each list item. The characters “id” are reserved by Applescript for other use and have to be enclosed in a string.
SC
I don’t have iView MediaPro and I don’t know how you are getting your input list nor if the application allows you to extract the window from an object reference but assuming that it can, simply putting your repeat in an application tell block should suffice:
tell application "iView MediaPro"
--get theInput, let's just say it's:
set theInput to {id 1850 of window 1, id 1853 of window 1, id 1849 of window 1, id 1854 of window 1, id 42 of window 3}
repeat with inputObject in theInput
set inputWindowName to name of window of inputObject
display dialog inputWindowName buttons {"Cancel", "OK"} default button 2 with icon 1 giving up after 1
end repeat
end tell
Jon
Model: PowerBook 1.25MHz
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)
Yup, this is my problem. It doesn’t look like iView MediaPro allows the window (or catalog) to be extracted from the object reference. This seems to be backed up by the script dictionary for the application, which doesn’t have “backpointers” from the objects to their containers.
I guess what I was wondering was whether there was a way in Applescript to get the container of an object? I’ve tried all the permutations I can think of (“container of inputObject” doesn’t work, for example) so I was sorta running out of gas.
For the moment, I’ll probably use sitcom’s trick of parsing the reference as a string but that seems a tad inelegant and might be liable to break if the object reference heirarchy gets changed.
Oh well. Writing Applescript always seems to come back to the Art Of The Possible.
Scott…
Browser: Safari 412
Operating System: Mac OS X (10.4)