• 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: Scripting Filepaths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Filepaths


  • Subject: Re: Scripting Filepaths
  • From: Chris Page <email@hidden>
  • Date: Thu, 30 Jul 2009 14:53:13 -0700

On Jul 30, 2009, at 1:23 PM, J. Stewart wrote:

On 7/30/09 at 11:48 AM, James Bensley <email@hidden> spake thusly:

set current_user to do shell script("whoami")
set file_path to "/Users/" & current_user & /Desktop/MyFile.abc"

OTH

set file_path to quoted form of posix path of ((path to "desk" as text) & "MyFile.abc")

Doesn't launch a shell, accomplishes the same thing in one line and is more reliable because the resulting path is properly escaped regarding spaces and other special (shell) characters.

Most importantly, it doesn't hard-code how a user name is mapped to a pathname. Never hard-code path elements like "/Users/" unless you have no alternative. And don't assume the user name returned by "whois" is the name of a directory inside "Users".


"path to" generally supplies the path to common directories.

--
Chris Page

 The other, other AppleScript Chris

_______________________________________________
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: Scripting Filepaths (From: "J. Stewart" <email@hidden>)

  • Prev by Date: Re: Excel (2004) Hidden rows show up in tab delimited text file
  • Next by Date: Re: Scripting Filepaths
  • Previous by thread: Re: Scripting Filepaths
  • Next by thread: Re: Scripting Filepaths
  • Index(es):
    • Date
    • Thread