Hi guys,
I have a perfectly working applecsript for TextWrangler (below: all the stuff between the first else and last end if) and only wanted to make it activate textwrangler if i work in another application; if i'm in textwrangler i want it to run the rest of the script. however, when i try to run this the applescript editor gives me an error complaining that "Expected end but found on." referring to the "on ComputeTempFileName(originalFile)" line.
I'm new to this... and none of what i tried worked.
Would you have any idea how to fix this? thanks a lot. Josef
if name of current application is not "textwrangler"
tell application "textwrangler" to activate
else
tell application "TextWrangler"
set thecontents to the selection in window 1 as string
set theOriginalFile to file of document 1
if thecontents is "" then
tell text window 1
select line (startLine of selection)
end tell
end if
set thecontents to the selection in window 1 as string
set theOriginalFile to file of document 1
end tell
set thecontents to thecontents & return & "erase temp.do" & return & "exit"
set tempFile to my ComputeTempFileName(theOriginalFile)
my write_to_file(thecontents, tempFile, false)
tell application "Finder" to set filename to tempFile as alias
tell application "StataSE"
activate
get name
end tell
if name of application "StataSE" = "StataSE" then
tell application "System Events"
tell process "StataSE"
set frontmost to true
tell window 1
get name
end tell
if name of window 1 = "data editor" then
tell window "data editor"
keystroke "w" using command down
end tell
end if
end tell
end tell
tell application "StataSE"
activate
open filename
end tell
end if
on ComputeTempFileName(originalFile)
tell application "Finder"
set c to container of originalFile
set t to (c as string) & "temp.do"
end tell
return t
end ComputeTempFileName
on write_to_file(this_data, target_file, append_data)
tell application "Finder"
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end tell
end write_to_file
end if
I have a perfectly working applecsript for TextWrangler (below: all the stuff between the first else and last end if) and only wanted to make it activate textwrangler if i work in another application; if i'm in textwrangler i want it to run the rest of the script. however, when i try to run this the applescript editor gives me an error complaining that "Expected end but found on." referring to the "on ComputeTempFileName(originalFile)" line.
I'm new to this... and none of what i tried worked.
Would you have any idea how to fix this? thanks a lot. Josef
if name of current application is not "textwrangler"
tell application "textwrangler" to activate
else
tell application "TextWrangler"
set thecontents to the selection in window 1 as string
set theOriginalFile to file of document 1
if thecontents is "" then
tell text window 1
select line (startLine of selection)
end tell
end if
set thecontents to the selection in window 1 as string
set theOriginalFile to file of document 1
end tell
set thecontents to thecontents & return & "erase temp.do" & return & "exit"
set tempFile to my ComputeTempFileName(theOriginalFile)
my write_to_file(thecontents, tempFile, false)
tell application "Finder" to set filename to tempFile as alias
tell application "StataSE"
activate
get name
end tell
if name of application "StataSE" = "StataSE" then
tell application "System Events"
tell process "StataSE"
set frontmost to true
tell window 1
get name
end tell
if name of window 1 = "data editor" then
tell window "data editor"
keystroke "w" using command down
end tell
end if
end tell
end tell
tell application "StataSE"
activate
open filename
end tell
end if
on ComputeTempFileName(originalFile)
tell application "Finder"
set c to container of originalFile
set t to (c as string) & "temp.do"
end tell
return t
end ComputeTempFileName
on write_to_file(this_data, target_file, append_data)
tell application "Finder"
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end tell
end write_to_file
end if