I have a small problem at the moment, i am trying to export a string to a file without a dialog box.
but i cannot seem to get it to work.
File script.txt
Directory is /usr/local/script/
I am very new to applescript so any help would be great
I have a small problem at the moment, i am trying to export a string to a file without a dialog box.
but i cannot seem to get it to work.
File script.txt
Directory is /usr/local/script/
I am very new to applescript so any help would be great
try
set the open_target_file to open for access file target_file with write permission
set eof of the open_target_file to 0
write newString to the open_target_file starting at eof
close access the open_target_file
on error
close access file target_file
end try
I’ve answered this at MacOSXHints. I’ll post my reply here as well.
Using do shell script:
set myString to "Hello, World!"
try
do shell script "echo " & quoted form of myString & " > " & ¬
quoted form of POSIX path of ((path to desktop as Unicode text) & "AS Test 1.txt")
on error errorMsg number errorNum
display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try
Using AppleScript’s write command:
set myString to "Hello, World!"
try
set fileRef to open for access file ((path to desktop as Unicode text) & "AS Test 2.txt") with write permission
set eof of fileRef to 0 --Use this to overwrite an existing file
write myString to fileRef
close access fileRef
on error errorMsg number errorNum
try
close access fileRef
end try
display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try