Write text to file question - newbie

Hi, please pardon this newbie question, I’ve been Googling and searching your forum but can’t get my script to work:



set file_write to open for access file ("/Users/USERNAME/Documents/testfile.txt") with write permission
write my_string to file_write starting at 0
close access file_write


My eventual goal is to take today’s date, change it into 4 days ago, and write it to a specific place in Thunderbird’s filter .dat file so I can filter on messages 4 days old. Thunderbird doesn’t have a dictionary I guess. I got the date part done, now I’m experimenting with writing to the file and banging my head agains the wall!

Model: Cube
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

Hi dxl,

Your script uses the unix slash style reference, but you need an AppleScript style reference for the ‘open for access’ command. The following script show how to coerce the different references:

set alias_ref1 to (choose file) – AppleScript alias reference
set posix_path to (POSIX path of alias_ref1) – unix slash style reference
set file_spec to (posix_path as POSIX file) – file specification
set alias_ref2 to (file_spec as alias) – back to alias reference

Note that strings and references are different:

“Macintosh HD:Applications:TextEdit.app:” – string

alias “Macintosh HD:Applications:TextEdit.app:” – alias reference

file “Macintosh HD:Applications:TextEdit.app:” – file specification

gl,

Wow, thanks for the fast and helpful response! I’ve got the script working now.

I would have never guessed that my problem was the style of reference path.

What I’ve got now is a script that changes the mail filter I use in Mozilla Thunderbird. Thunderbird allows you to set up a filter for messages received before a certain date, but you have to enter in the date by hand. Now if I run the script before I open Thunderbird, the filter date will change to be 4 days ago. FWIW

Model: Cube
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

Hi dxl,

Glad you got it working. Be careful when writing files like that.

gl,