• 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: ongoing Senior moments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ongoing Senior moments


  • Subject: Re: ongoing Senior moments
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 09 Nov 2014 15:06:19 -0600

On Nov 09, 2014, at 13:03, Robert Poland <email@hidden> wrote:
This script snippet confounds me;

tell application "Finder"
    set theFolder to "" & "~/Pictures/APOD ƒ/"
    set theFolder to  (choose file default location alias the folder
end tell

I keep getting error; Expected “,” but found end of line.
Using "~/Pictures/APOD ƒ/“ in place of theFolder doesn’t help.
After restarting Smile I get the error “file Alias "~/Pictures:APOD ƒ/“ of <<script>> wasn’t found.
______________________________________________________________________

Hey Bob,

You've forgotten that AppleScript absolutely and unequivocally does not understand Tilde-Path notation. 

The Finder itself doesn't like the Posix Path to Posix File coercion even though it will accept the Posix File class.

It's so easy to get tripped up by using different path types or file types that I think it's a good practice to always stick with aliases UNLESS you have a good reason to use something else (especially when working with the Finder).

Personally I would use this notation (and I have a script to automatically create it):

set theFolderPath to alias ((path to pictures folder as text) & "APOD ƒ:")

That said: I think this is actually easier to read:

set theFolderPath to "~/Pictures/APOD ƒ/"

So I do in fact use Tilde-Path notation with some frequency, however if I'm not using the shell I usually turn it into an alias immediately.

So, let's fix your code by expanding the ~/ token:

------------------------------------------------------------------------------------
set theFolderPath to "~/Pictures/APOD ƒ/"

set theFolderAlias to alias POSIX file expandTildePath(theFolderPath)
set theFolderPosixFile to POSIX file expandTildePath(theFolderPath)
set theFolderPosixPath to expandTildePath(theFolderPath)

tell application "Finder"
  set theFile1 to (choose file default location theFolderPosixPath) # Works fine (on 10.9.5).
  # set theFileX to (POSIX file (expandTildePath(theFolderPath) of me)) # The Finder doesn't like it!
  set theFile2 to (choose file default location theFolderAlias) # Works fine.
  set theFile3 to (choose file default location theFolderPosixFile) # Works fine.
end tell

------------------------------------------------------------------------------------
on expandTildePath(posixPath)
  if posixPath = "~/" then
    set posixPath to POSIX path of (path to home folder)
  else if posixPath starts with "~/" then
    set posixPath to (POSIX path of (path to home folder as text)) & text 3 thru -1 of posixPath
  end if
  return posixPath
end expandTildePath
------------------------------------------------------------------------------------

Note that choose file is happy to accept:

 alias
 posix file
 posix path

as the target of the default location.

--
Best Regards,
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

  • Follow-Ups:
    • Re: ongoing Senior moments
      • From: Shane Stanley <email@hidden>
References: 
 >ongoing Senior moments (From: Robert Poland <email@hidden>)

  • Prev by Date: Re: ongoing Senior moments
  • Next by Date: Re: ongoing Senior moments
  • Previous by thread: Re: ongoing Senior moments
  • Next by thread: Re: ongoing Senior moments
  • Index(es):
    • Date
    • Thread