• 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: Basic script blues ;-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic script blues ;-)


  • Subject: Re: Basic script blues ;-)
  • From: kai <email@hidden>
  • Date: Sun, 27 Mar 2005 21:38:18 +0100


On Sun, 27 Mar 2005 20:43:22 +0200, Bernard Azancot wrote:

Why is the
Folder1 to folder ("IBM 01:Users:parents:Desktop:Foo")
considered as an alias to a folder?

It's not, Bernard...

--------

Within a Finder tell block, < folder "IBM 01:Users:parents:Desktop:Foo" > will be treated as a Finder reference:

folder "Foo" of folder "Desktop" of folder "parents" of folder "Users" of disk "IBM 01" of application "Finder"

Outside of a Finder tell block, the statement will probably not even compile.

--------

An alias, on the other hand will look like this:

alias "IBM 01:Users:parents:Desktop:Foo:"

This could be used either inside a Finder tell block, another application tell block - or even outside any tell block.

--------

The '&' symbol denotes a concatenation operator - which can only operate on text (plain text, Unicode text, styled text, etc.) - it can't combine objects of different classes without some form of implicit or explicit coercion to text first.

--------

Whats the trick of
if not (exists folder ("" & Folder1 & ":Folder2"))

It's a concatenation trick that invokes an automatic AppleScript coercion. It means the equivalent of:


if not (exists folder ((Folder1 as string) & "Folder2"))

(I removed the leading colon of ":Folder2", since it shouldn't be necessary when coercing to string from a Finder reference of a folder.) Note how the reference to 'Folder1' is first coerced to a string and then concatenated with the string "Folder2" - before being presented to the Finder as a folder reference.

For more information about concatenation, see:

http://developer.apple.com/documentation/AppleScript/Conceptual/ AppleScriptLangGuide/AppleScript.a9.html#30970

--------

Paul has already given you some very good advice about how to deal with the issue that you were encountering, particularly in relation to the concatenation of paths.

In addition, you could also use Finder references in this way:

tell application "Finder"
set folder1 to folder "IBM 01:Users:parents:Desktop:Foo"
if not (exists folder "Folder2" of folder1) then make new folder at folder1 with properties {name:"Folder2"}
end tell


--------

The important thing in all this is to try and avoid confusion over objects of different classes. :-)

I referred above to a section of the AppleScript Language Guide. In spite of its age and lack of updates, I still believe that the ASLG is an invaluable source of reference for anyone involved in creating AppleScript solutions. In fact, I'm pretty sure that many of the leading contributors to this list still refer to it on a regular basis. You can view it here:

http://developer.apple.com/documentation/AppleScript/Conceptual/ AppleScriptLangGuide/

Better still, download a copy of the PDF version to read at your leisure from here:

http://developer.apple.com/referencelibrary/API_Fundamentals/ AppleScript-api-date.html

---
kai

_______________________________________________
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


  • Prev by Date: Re: Print current record from FileMaker?
  • Next by Date: Smile crash
  • Previous by thread: Re: Entourage, Photoshop and a Folder Action
  • Next by thread: Re: Basic script blues ;-)
  • Index(es):
    • Date
    • Thread