• 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: AppleScript-Users Digest, Vol 4, Issue 2
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Users Digest, Vol 4, Issue 2


  • Subject: Re: AppleScript-Users Digest, Vol 4, Issue 2
  • From: Barry Wainwright <email@hidden>
  • Date: Tue, 02 Jan 2007 20:17:16 +0000
  • Thread-topic: AppleScript-Users Digest, Vol 4, Issue 2

It's a bit of shorthand - it becomes a bit clearer if you move things
around, and use an application tell block as the main target for the script:

tell app "Finder"
    if (exists of finder window 1) then
        set current view of finder window 1 to list view
        set bounds of finder window 1 to {5, 45, 1000, 900}
        -- rest of code
    end if
end tell

'exists' is actually a command from standard additions, I'm using it like a
property of the window to emphasise this point. More common would be to use
a construct like 'if window 1 exists', or 'if exists window 1'.

However, to avoid having all those 'of window 1' bits on every line, you can
'tell' window 1 to be the target for all the commands:

tell app "Finder"
    tell finder window 1
        if exists then
        set current view to list view
        set bounds to {5, 45, 1000, 900}
        -- rest of code
        end if
    end tell
end tell

All the later commands then get directed to 'finder window 1' and it doesn't
need to be specifically stated.

The final contraction is to collapse the inner 'tell...end tell' construct
in a 'tell [target] to...' command. The 'if' statement then being the single
command parameter to this construct and you get:

tell app "Finder"
    tell finder window 1 to (if ... Then... End if)
End tell

--
Barry


> From: Bryan Lockwood <email@hidden>
> Date: Tue, 02 Jan 2007 11:31:27 -0800
> To: <email@hidden>
> Conversation: AppleScript-Users Digest, Vol 4, Issue 2
> Subject: Re: AppleScript-Users Digest, Vol 4, Issue 2
>
> Perhaps I'm just not yet steeped enough in AppleScript, but the following
> snippet, taken from a recent digest, leaves me totally nonplussed.
>
> How in the devil am I supposed to parse the line below which reads " tell
> Finder window 1 to if exists then". I don't get this at all (although, of
> course, I can figure out what it means, it seems to me totally
> ungrammatical. Wish I had a yacc grammar for AppleScript, but I know it's
> impossible.) This makes split infinitives look beautiful. Anyhow, so much
> for readibility.
>
> I'd be grateful for any further enlightenment.
>
> Bryan
>
>
>> From: "email@hidden"
>> <email@hidden>
>> Reply-To: <email@hidden>
>> Date: Mon,  1 Jan 2007 16:07:06 -0800 (PST)
>> To: <email@hidden>
>> Subject: AppleScript-Users Digest, Vol 4, Issue 2
>>
>> tell application "Finder"
>> activate
>> tell Finder window 1 to if exists then
>> set current view to list view
>> set bounds to {5, 45, 1000, 900}
>> set v to toolbar visible
>> set toolbar visible to not v
>> set toolbar visible to v
>> end if
>> end tell
>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/mailman//archives/applescript-users
>
> This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: AppleScript-Users Digest, Vol 4, Issue 2
      • From: Axel Luttgens <email@hidden>
References: 
 >Re: AppleScript-Users Digest, Vol 4, Issue 2 (From: Bryan Lockwood <email@hidden>)

  • Prev by Date: Re: AppleScript-Users Digest, Vol 4, Issue 2
  • Next by Date: Mail.app "reply" verb returning nothing
  • Previous by thread: Re: AppleScript-Users Digest, Vol 4, Issue 2
  • Next by thread: Re: AppleScript-Users Digest, Vol 4, Issue 2
  • Index(es):
    • Date
    • Thread