• 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: Fwd: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)


  • Subject: Re: Fwd: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • From: Ted Wrigley <email@hidden>
  • Date: Wed, 19 Mar 2014 08:37:38 -0700

Ok, a two-rule style guide for tell blocks:

1. Keep tell blocks focused: as much as possible, they should only contain statements related to the application or object being targeted.  Where you must refer to handlers from osaxen or the main script from within a tell block, use the ‘my’ or ‘of me’ specifier.

2. Avoid nesting tell blocks except where the objects being targeted are themselves nested. If there’s a practical reason to nest tell blocks for unrelated objects or applications, put the contained tell bock in a handler and call it rather than writing it directly into the other tell block.

example:

set aPath to POSIX file "/some/file/path" -- Standard Additions command, use outside of tell block

tell application "Finder"
reveal aPath -- reveal is a command specific to the Finder
my openFileInExcel(path) -- 'my' keyword tells the Finder to pass the request to the main script
end tell

on openFileInExcel(p)
-- call excel in a handler to give it its own context
tell application "Microsoft Excel"
open p
end tell
end openFileInExcel

Scripts can always be restructured to follow these rules with a bit of planning.

On Mar 19, 2014, at 7:12 AM, email@hidden wrote:

From: Alastair Leith <email@hidden>
Subject: Fwd: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
Date: March 19, 2014 at 4:48:13 AM PDT
To: asu <email@hidden>


I'm very interested if anyone has any philosophical, style guide or optimisation type answers and/or preferences to the question of when to use tell blocks. And how to use tell blocks in nested or unnested ways (pref for parallel or series usage).


 _______________________________________________
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/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: ID of a Disk
  • Next by Date: Re: AppleScript-Users Digest, Vol 11, Issue 117
  • Previous by thread: Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • Next by thread: Re: AppleScript-Users Digest, Vol 11, Issue 117
  • Index(es):
    • Date
    • Thread