Getting a specific path to a file to attach via Entourage

Hello:

I am new to AppleScript, and after some research and loads of attempts, I have finally decided to post to the experts!

I have been trying to setup a Script that will do the following:

1.- Open a website, and save it as a PDF

– code used:

tell application “Safari”
activate
open location “http://mncomacapp01/medpda/tools/whatsup.py
delay 4
tell application “System Events” to keystroke “p” using {command down}
delay 1
end tell
tell application “System Events” to keystroke “p” using {command down}
delay 1
set thePath to “:Users:username:Desktop:Folde1:Folde2:Folder3:”
set theDate to do shell script “date ‘+%m-%d-20%y-%H%Mhrs’”
tell application “System Events”
tell window 1 to thePath
keystroke theDate as text
delay 0.5
– key code 36
end tell

– Now, so far this creates the PDF file I will need to attach, but I have battled with the following part in both sides, how can I interact with the save window to ensure that it goes to a specific path?

– ** the next part of the code is the one which creates the message…
Here is the only way I have managed to get the script to navigate to the actual file, I am sure there is a much easer cleaner and elegant way to do this!

tell application “Microsoft Entourage”
activate
delay 1
set theDate to do shell script “date ‘+%m-%d-20%y-%H%Mhrs’”
set theSubject to “What’s up report for " & theDate as text
set theBody to “What’s up report for today”
set StartFolderSelection to “:Users:username:Desktop:Folder1:Folder2:Folder3:”
→ set theAttachment to choose file StartFolderSelection
set theRecipients to {{address:{display name:“John Doe”, address:"jdoe@server.com”}, recipient type:to recipient}, {address:{display name:“Jane Doe”, address:"janedoe@server2.com"}, recipient type:bcc recipient}}
set theMessage to make new outgoing message with properties {recipient:theRecipients, subject:theSubject, content:theBody}
open theMessage
delay 3

tell application "System Events" to keystroke "e" using {command down}
delay 2
--> Go up
tell application "System Events" to key code 48
delay 0.2
tell application "System Events" to key code 48
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2
tell application "System Events" to key code 126
delay 0.2

--> Go down
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 124
delay 0.2
tell application "System Events" to key code 48
delay 1
--> 
tell application "System Events" to key code 125
delay 0.3
tell application "System Events" to key code 125
delay 0.3
tell application "System Events" to keystroke "Folder1"
delay 0.2
delay 1
tell application "System Events" to key code 124
delay 1
tell application "System Events" to keystroke "Folder2"
delay 0.3
tell application "System Events" to key code 124
delay 1
tell application "System Events" to keystroke "Folder3"
delay 0.5
tell application "System Events" to key code 124
delay 1
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 125
delay 0.2
tell application "System Events" to key code 36
delay 1
tell application "System Events" to key code 36 using {command down}

end tell

– Please help me understand how to work with the interacting windows such as the one that pops up on save and on Attach,

An other thing that I have noticed is, if I have the script setup to run at a certain time, and the machine is on stand by, the Screen saver Password window will take the “keystroke” commands and type them there instead of the desired window.

thanks!!

HT

Model: MacBook Pro 15in
AppleScript: 2.1.2
Browser: Safari 534.50
Operating System: Mac OS X (10.6)

Hi,

take a look at this thread: http://macscripter.net/viewtopic.php?id=36776

Thanks Stefan for your reply…

After checking some of the scripts, I see big differences between them and mine for sure, I still find though that you have to manually choose the path where you want to set your PDF file, is there a way to set for example:

:Users:username:Desktop:Reports:Year:Month:

as the path where the save window should save the file into?

Same case for the Attach file window in Entourage ( My guess it would be the same way)

thanks

HT

instead of


set SaveFolder to choose folder with prompt "Select Folder to Save PDF Files"

you can “hard-code”


set SaveFolder to ((path to desktop as text) & "Reports:Year:Month:")

path to desktop returns the path to the desktop of the current user

Don’t think in windows, think in paths.
As you have the path to save the PDF you can use it directly in Entourage

I am feeling very stupid here…

I understand that using …

set saveFile to ((path to desktop as text) & “Reports:Year:Month:”)

will give me a string as text with the path…

How can I invoke this path to reflect it when saving the file…

So far … I get a window that opens, writes the name of the file to safe, but it does not go to the path I want the file in.

I am maybe suffering some kind of mental blockage!!

I am sorry for my poof understanding…

Thanks

H T

this portion of the code in the mentioned thread


.
      tell window "Save"
           keystroke "g" using {command down, shift down}
           repeat until exists sheet 1
               delay 0.2
           end repeat
           tell sheet 1
               --Subject_Added Peter to test how to pass file name
               set value of text field 1 to POSIX path of SaveFolder
               click button "Go"
           end tell
           repeat while exists sheet 1
               delay 0.2
           end repeat
           click button "Save"
       end tell
   end tell
.
end tell

enters the destination path (variable SaveFolder) into the Save window and “clicks” the Save button.
In your case you have to append the file name to the string path.

The string path can be used afterwards to specify the path in Entourage

Thank you so much Stefan…

After studying your script and tinkering with some of my own making I finally got it to work…

The final Script is depicted bellow in hopes that this may some day help someone else too.

→ Safari phase

tell application “Safari”
activate
open location “http://website.to copy”
delay 4
tell application “System Events” to keystroke “p” using {command down}
delay 1
end tell
tell application “System Events” to keystroke “p” using {command down}
set theDate to do shell script “date ‘+%m-%d-20%y-%H%Mhrs’”
delay 1
set the clipboard to theDate
tell application “System Events” to keystroke “v” using {command down}
delay 0.5
tell application “System Events” to keystroke “g” using {command down, shift down}
delay 1
tell application “System Events” to keystroke “/Users/youruser/Desktop/Folder1/Folder2/Folder3/”
tell application “System Events” to key code 36
delay 2
tell application “System Events” to key code 36

—> Entourage phase

tell application “Microsoft Entourage”
activate
delay 1
set theSubject to “What’s up report for " & theDate as text
set theBody to “What’s up report for today”
set theRecipients to {{address:{display name:“John Doe”, address:"johndoe@server.com”}, recipient type:to recipient}, {address:{display name:“Jane Doe”, address:"janedoe@server.com"}, recipient type:bcc recipient}}
set theMessage to make new outgoing message with properties {recipient:theRecipients, subject:theSubject, content:theBody}
open theMessage
delay 3

tell application "System Events" to keystroke "e" using {command down}
delay 1
tell application "System Events" to keystroke "g" using {command down, shift down}
delay 0.5
tell application "System Events" to keystroke "/Users/youruser/Desktop/Folder1/Folder2/Folder3/"
tell application "System Events" to key code 36
delay 0.2
tell application "System Events"
	key code 124
	delay 0.5
	key code 125 using {option down}
	delay 0.2
	tell application "System Events" to key code 36
	delay 0.5
	tell application "System Events" to key code 36 using {command down}
end tell

end tell