Savel Panel problems

I am trying to use the oath returned from a save panel but it keeps causing errors.

The path returned of the save panel is some thing like “Users/Sharky/Desktop/Test.txt” but when I try to use this as is with an ‘open for access’ command, I get a ‘bad file name’ error. I could fix the slashes in the path with TIDs but should I have to and would that make any difference?

Any guidance n using the 'save panel" to dictate the save path for write to file command would be great.

Thanks
S

Hi,

wrong path syntax is one of the most common errors (and misunderstandings) in AppleScript.
The save panel handler returns a POSIX path (/) but plain AppleScript (and also the read/write commands) works only with HFS paths (:).

You have to coerce the POSIX path to a HFS path like this

set targetFile to "Users/Sharky/Desktop/Test.txt" as POSIX file
set ff to open for access targetFile with write permission
.

Thanks Stefan.

Nearly there!! Now I get and error :

Never go these issues when just trying to write to standard file.

Where am I going wrong?

Thanks
S

look at my post!

it’s not

set ff to open for access file targetFile with write permission

it’s

set ff to open for access targetFile with write permission

if this is not the cause, use

set targetFile to "Users/Sharky/Desktop/Test.txt" as POSIX file as text
set ff to open for access file targetFile with write permission

Stefan

Thanks for the tip. I had just about got there myself

I got it working by a combination of adding the ‘as text’ to coerce the POSIX path and remove the extra ‘file’ from the ‘open for access…’ command.

You verified my guess work!

Thanks again.
:slight_smile: