0

So there goes four hours of my life that I will never get back.

I'm trying to do something seemingly simple...

I want to open a file select dialog box and specify the default location.

I actually got this to work using the following...

choose file with prompt "Please choose a file:" of type {"XLSX", "APPL"} 
default location "/Users/lowken/Dropbox/"

This works and does exactly what I want (the file dialog opens up in the Dropbox folder).

However when I try to use a string variable it doesn't work...

set strPath to "/Users/lowken/Dropbox/"

choose file with prompt "Please choose a file:" of type {"XLSX", "APPL"} 
default location strPath

Now the dialog box opens in the root directory of the hard drive :-(

It seems that the default location is being ignored however if the path is not correct Applescript does raise a error.

I've tried casting the value as a string. I even tried to use the POSIX format...

"Macintosh HD:Users:lowken:Dropbox"

This didn't format didn't work at all.

I'm running OS X Yosemite 10.10.4 on a mid 2012 MacBook Pro.

Can anyone help me?

  • script worked fine for me. Maybe a restart to clear things out, or copy and paste script to new editor window. – tron_jones Jul 18 '15 at 21:26
  • It works but it doesn't open to the folder specified by srtPath. – codingguy3000 Jul 18 '15 at 21:56
  • thats what I'm saying, it does open to the strPath for me. /Users/username/Dropbox/ and shows my files inside of dropbox. – tron_jones Jul 18 '15 at 23:44
  • Like tron_jones, I have had no trouble running either of your scripts. Have you tried setting the variable to a different path? Perhaps it's an issue with your Dropbox directory. – aaplmath Jul 19 '15 at 15:20
  • At some point, Apple changed how things precompile in AppleScript. I remember running into this problem back in 2012. In my case, there was no workaround. I had to use the string literal. That was not the case with earlier versions of AppleScript. – Wayfaring Stranger Feb 21 '17 at 15:44
3

Both scripts don't work for me. The problem is that the default location parameter needs to be of type alias. You can fix it by adding POSIX file in front of your path (the path does need to exist, otherwise you also get an error message):

set strPath to POSIX file "/Users/lowken/Dropbox/"

choose file with prompt "Please choose a file:" of type {"XLSX", "APPL"} ¬
    default location strPath

Or you could use the "old style" HFS format:

set strPath to alias "Macintosh HD:Users:lowken:Dropbox"

choose file with prompt "Please choose a file:" of type {"XLSX", "APPL"} ¬
    default location strPath

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .