Help with Applescript reference syntax?

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. :slight_smile:

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.

Thanks!

Scott…

set theList 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}

Those window id’s are items of theList. So “x” of “y” is item (x as integer) of theList or item 2 of theList → “id 1853 of window 1”

This will give you the repeat loop:

http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.13.htm

and has the syntax for bustin those lists down to get what you need. You can do some cool variable exchanges with lists to do creative stuff. ie:

set WinID1854 to 4 as number
get (item WinID1854) of theList → “id 1854 of window 1”

SC

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)

OK gotcha-


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)

Jon,

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.

:slight_smile:

Scott…

Browser: Safari 412
Operating System: Mac OS X (10.4)

Just guess here (I haven’t tested this), but couldn’t you do the following:

set inputWindowName to window of inputObject

Like I said, this is just off the top of my head, so to speak.

Brad Bumgarner, CTA

Model: G5 iMac
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)