• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: List Problem (I think) Disguised as a GraphicConverter Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List Problem (I think) Disguised as a GraphicConverter Problem


  • Subject: Re: List Problem (I think) Disguised as a GraphicConverter Problem
  • From: Gil Dawson <email@hidden>
  • Date: Tue, 8 Mar 2005 18:20:01 -0800

At 8:10 PM -0500 3/8/05, Jonathan Levi, M.D. wrote:
--------------------------------
the Script:

(*
  gcActivateWindow.scpt -- drives a subroutine gcActivateWindow()
  to make GraphicConverter activate a given window. JL 3/8/2005.
*)

on gcActivateWindow(wname)
  tell application "GraphicConverter" to set f to file of window wname
  tell application "Finder" to open f --needed to bring window to front
end gcActivateWindow


set gcWindowNames to {"a.pict (RGB)", "b.pict (RGB)"}

gcActivateWindow("a.pict (RGB)") --works

repeat with i from 1 to (count items of gcWindowNames) --works
  gcActivateWindow(item i of gcWindowNames)
end repeat

repeat with wname in items of gcWindowNames --doesn't work
  gcActivateWindow(wname)
end repeat

--------------------------------

I just finished reading about this in The Definitive Guide. As Matt explains it, the problem is that, in the last case, wname is a reference. Nevermind what the log says, the value of wname when you call the subroutine is an incantation, something Matt calls "frozen words", like, "item 1 of gcWindowNames" -- it isn't the item, but a "reference" to it. Your subroutine wants to see the item, not any frozen words.


To dereference the reference, get its contents.  Try

    gcActivateWindow(contents of wname)

Matt also mentions that getting the contents of some thing that isn't a reference simply returns the thing itself, which is lucky because it suggests a way to make your subroutine a bit more versatile. So, alternatively, in gcActivateWindow, try

tell application "GraphicConverter" to set f to file of window (contents of wname)

Matt also points out that telling whether a particular construct is going to return a thing or a reference to that thing is not readily predictable by any obvious rules. You just have to try and see, or copy from examples. It's not even easy to tell whether a thing is a reference, or not, because references lie about their class and will tell you ("class of wname") that they are the thing they are referencing. One way that might work in your case here is to attempt to coerce your variable to a reference:

repeat with wname in items of gcWindowNames --doesn't work
   wname as reference -- will throw an error if it isn't
   gcActivateWindow(wname)
 end repeat

The only thing that can legally be coerced to a reference is a reference (useful, huh?), so you'll get an error if it isn't.

I recommend the book. It's fabulous. But hurry-- some things have already changed!

--Gil

P.S. I guess I should confess that I haven't tested these suggestions. =|:-(
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >List Problem (I think) Disguised as a GraphicConverter Problem (From: "Jonathan Levi, M.D." <email@hidden>)

  • Prev by Date: Re: List Problem (I think) Disguised as a GraphicConverter Problem
  • Next by Date: Filemaker Communications error
  • Previous by thread: Re: List Problem (I think) Disguised as a GraphicConverter Problem
  • Next by thread: FASTEST Record Find with FileMaker Pro 7?
  • Index(es):
    • Date
    • Thread