• 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: "a reference to"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "a reference to"


  • Subject: Re: "a reference to"
  • From: has <email@hidden>
  • Date: Thu, 17 Jan 2008 20:09:48 +0000

On 17 Jan 2008, at 18:57, Scott Babcock wrote:

Sorry... I failed to explain the purpose of the 'reference' coercion. This code is derived from "AppleScript: The Definitive Guide" by Matt Nueburg, in the section titled "Identifying References".

AppleScript provides no direct way to determine that it's handed you a reference instead of a local object.

References are local objects [1]. I assume you mean 'references to application objects'.



One of the workarounds for this deficiency is to attempt to coerce the item in question to 'reference'. Since non-reference items cannot be coerced to 'reference', the absence of an error gives indirect evidence that an item is a reference.

Personally, I'd do something like:

on isReference(obj)
	return (count {obj} each reference) > 0
end isReference


Bear in mind that neither technique will distinguish between references to local objects and references to application objects, e.g.:


isReference("Hello World") --> false
isReference(document 1 of application "TextEdit") --> true
isReference(a reference to item 1 of {1, 2, 3}) --> true


Things are rather more straightforward in appscript, FWIW, since all the standard instance methods are kept unchanged, e.g.:


#!/usr/bin/ruby

require 'appscript'; include Appscript

obj = app('Finder').home.get
p obj.is_a?(Appscript::Reference) # true

obj = app('Finder').home.name.get
p obj.is_a?(Appscript::Reference) # false


has

[1] Of type 'reference', funnily enough, although as you say there's no way to obtain that information directly since they're designed to be largely transparent in their behaviour.
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org


_______________________________________________
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
References: 
 >RE: "a reference to" (From: Scott Babcock <email@hidden>)

  • Prev by Date: RE: "a reference to"
  • Next by Date: RE: Obfuscations and little white lies
  • Previous by thread: RE: "a reference to"
  • Next by thread: Re: "a reference to"
  • Index(es):
    • Date
    • Thread