I wish to generate a file name into which I will ask TextWrangler to Save some manipulated text.
The TextWrangler .sdef says that it needs an alias for the destination for its Save operation:
______________________________________________________________________
Hey Gil,
From the alias class in the Applescript Language Guide:
alias A persistent reference to an existing file, folder, or volume in the file system.
This is one of those extremely frustrating little gotchas in AppleScript.
Sdefs don't always get it right - nor are they always complete. :)
You'd think it would say path or file-spec, but instead it says alias and makes people bang their heads against the wall. (I did too when I first messed with saving from BBEdit years ago.)
You can do something like this if the file already exists:
-------------------------------------------------------------------------------------------
set _file to alias ((path to downloads folder as text) & "test.txt")
set _text to " 01 Now is the time for all good men to come to the aid of their country. 02 Now is the time for all good men to come to the aid of their country. 03 Now is the time for all good men to come to the aid of their country. 04 Now is the time for all good men to come to the aid of their country. 05 Now is the time for all good men to come to the aid of their country. "
tell application "BBEdit" activate make new text document tell front document set its text to _text save to _file end tell open _file end tell
-------------------------------------------------------------------------------------------
But the contents of that file will be destroyed.
Losing the alias will let you create a new file:
set _file to ((path to downloads folder as text) & "Test 2.txt")
Some apps want an HFS path and won't take a Posix Path, although this problem is slowly receding in actively developed apps.
-- Best Regards, Chris
|