• 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: Madness & frustration... What is a file? What is a Path?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Madness & frustration... What is a file? What is a Path?


  • Subject: Re: Madness & frustration... What is a file? What is a Path?
  • From: Michelle Steiner <email@hidden>
  • Date: Wed, 12 May 2004 09:23:53 -0700

On May 12, 2004, at 7:14 AM, Cliff Pruitt wrote:

Tell Application "Whatever"
set homePath to path to home folder
set theFile to homePath & ":Documents:Folder 1:Folder 2:file.txt"
open theFile
End Tell

It seems like it should be straightforward but for some reason it never works the way I think it will...

"path to" yields an alias.

In the next line you're trying to concatenate an alias and a string. When a script tries to concatenate two unlike elements, Applescript tries to coerce the second element into the class of the first. It can't coerce a string into an alias. When it can't make the proper coercion, it combines them into a list.

So, theFile is a list, not an alias, so the Open command fails.

The proper way to do the above is

set homePath to path to home folder
set theFile to homePath & ":Documents:Folder 1:Folder 2:file.txt"
open theFile

Even more better:

set docsPath to path to documents folder
set theFile to docsPath & "Folder 1:Folder 2:file.txt"
open theFile

Other comments:

The "tell" wrapper is not needed. Setting the path works is done by standard additions. Opening a file causes it to open with the application whose icon it has.

Also, an alias (and therefore a string generated from that alias) contains the final colon, so putting an initial colon in the string you're appending will generate an error.

I'll leave your questions about theory for others to answer.

-- Michelle

--
if u cn rd ths u cn gt a gd jb, bt if u rt lk ths u r a mrn.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Madness & frustration... What is a file? What is a Path?
      • From: Doug McNutt <email@hidden>
References: 
 >Madness & frustration... What is a file? What is a Path? (From: Cliff Pruitt <email@hidden>)

  • Prev by Date: Re: scripting keychain access - login keychain
  • Next by Date: Re: Madness & frustration... What is a file? What is a Path?
  • Previous by thread: Madness & frustration... What is a file? What is a Path?
  • Next by thread: Re: Madness & frustration... What is a file? What is a Path?
  • Index(es):
    • Date
    • Thread