Struggling with syntax

I get an error in the first if - then statement. I cannot seem to get the syntax right.

the tell block does for MSWord, does not seem to save the file - the script hangs and I think this is where. The logic flow seems ok, but again, I am struggling with syntax.

Thanks for your help.

tell application “System Events”
set pN to name of (some process whose visible is true and frontmost is true)
tell process pN to keystroke “c” using {command down}
end tell

if (exists ((path to documents folder as text) & “huddle.doc”)) then
tell application “Finder” to delete ((path to documents folder as text) & “huddle.doc”)
end if

tell application “Microsoft Word”
activate
delay 2
if not (exists document 1) then
make new document
end if
set left margin of page setup of document 1 to (inches to points inches 0.5)
set top margin of page setup of document 1 to (inches to points inches 0.5)
set right margin of page setup of document 1 to (inches to points inches 0.5)
set bottom margin of page setup of document 1 to (inches to points inches 0.5)
set header distance of page setup of document 1 to (inches to points inches 0)
set footer distance of page setup of document 1 to (inches to points inches 0)
paste special text object of document 1 data type paste text
tell text object of document 1 to set font size of font object to 12.0
auto format text range text object of document 1
save document 1 in ((path to documents folder as text) & “huddle.doc”)
delay 2
quit
end tell
set the_file to ((path to documents folder as text) & “huddle.doc”)
set the_subject to “Huddle”
tell application “Mail”
set new_message to make new outgoing message with properties {subject:the_subject, content:“Thought For The Day”, visible:true}
tell new_message
make new to recipient at end with properties {address:“lbennett@mdoyledds.com”}
make new attachment at end of first paragraph of content with properties {file name:the_file as alias}
end tell
end tell

Hi,

only the Finder (and System Events) knows about the existence of a file or folder.
AppleScript itself does not.


set huddleDoc to ((path to documents folder as text) & "huddle.doc")
tell application "Finder"
	if exists file huddleDoc then delete file huddleDoc
end tell

To leave any interference of System Events and the Finder out if this. You can try to make an alias of a path. If this fails, the file does not exist.

fileExistsAtPath("qsfqsfd")
--> false, unless you have a disk named that way
fileExistsAtPath(path to desktop folder as text)
--> true


on fileExistsAtPath(anAlias)
	try
		get anAlias as alias
		return true
	on error
		return false
	end try
end fileExistsAtPath

Hope it helps,
ief2

You need the Finder anyway to delete the file. :wink:

Unless you delete it with the rm-command.

do shell script "rm " & quoted form of posix path of (choose file)

This of couse doesn’t move the file to the trash, but immediatly deletes it.

But I think you can use the mv-command to move files, also to the trash.

do shell script "mv " & qouted form of posix path of (choose file) & " ~/.trash"

But then again, I’m not an expert with the terminal, so it could be that some things in this post are just wrong. And it’d be nice if someone would confirm or correct my lines of code.

Hope it all works,
ief2