I'm new to applescript and I'm having enormous trouble doing something which seems very basic. I'm trying to save a selected mail message in RTF format with attachments. Here is the errant script:
tell application "Mail"
activate
set AllMessages to selection
set myMessage to item 1 of AllMessages
open myMessage
tell application "System Events"
tell process "Mail"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "Save As…"
delay 2
keystroke "test"
click checkbox "Include Attachments" -- result: ERROR
end tell
end tell
end tell
end tell
end tell
end tell
You can try something like this:
set the clipboard to POSIX path of (path to desktop as text) & "test"
tell application "Mail"
open first item of (get selection)
activate
end tell
tell application "System Events"
tell process "Mail"
click menu item "Save As…" of menu 1 of menu bar item "File" of menu bar 1
delay 3
perform action "AXPress" of pop up button 1 of group 1 of sheet 1 of window 1
click menu item 1 of menu 1 of pop up button 1 of group 1 of sheet 1 of window 1
if value of checkbox "Include Attachments" of group 1 of sheet 1 of window 1 = 0 then
perform action "AXPress" of checkbox "Include Attachments" of group 1 of sheet 1 of window 1
end if
keystroke "g" using {command down, shift down}
keystroke "v" using {command down}
keystroke return
keystroke return
end tell
end tell
Related
I'm trying to set it so that there's no user interaction when I open up my illustrator file using applescript, but the standard:
tell application id "com.adobe.Illustrator"
activate
set user interaction level to never interact
open theFile without dialogs
doesn't work for this plugin I have installed that checks for white overprints.
If it were up to me I'd just uninstall the plugin but it's for a work pc.
I also tried clicking the button automatically (with help from Tim Joe) by using:
try
tell application "System Events"
tell process "Finder"
click button "OK" of window "Adobe Illustrator"
end tell
end tell
end try
and I've tried
tell application "System Events"
tell process "Adobe Illustrator"
keystroke return
end tell
end tell
Does anyone know a way of solving this?
below is the full code as it currently stands:
set saveLocation to ((path to desktop) as string) --place to save the files
set theFile to choose file with prompt "Choose the Illustrator file to get outlines on"
set outputFolder to choose folder with prompt "Select the output folder"
tell application "Finder" to set fileName to name of theFile
set fullPath to (saveLocation & fileName) --file path of new .ai
set fileName to (text 1 thru ((length of fileName) - 3) of fileName) --remove .ai from fileName
set olPath to text 1 thru ((length of fullPath) - 3) of fullPath & "_OL.ai" --path of outlined file
tell application id "com.adobe.Illustrator"
activate
ignoring application responses
open theFile without dialogs
end ignoring
tell application "System Events"
tell process "Adobe Illustrator"
repeat 60 times -- wait up to 60 seconds for WOPD window to appear
try
tell window "White Overprint Detector"
keystroke return
exit repeat
end tell
on error
delay 1
end try
end repeat
end tell
end tell
save current document in file fullPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save file to desktop
convert to paths (every text frame of current document) --convert text to paths
save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save another copy to desktop with name + _OL.ai
end tell
tell application "Finder"
set newFolder to make new folder at saveLocation with properties {name:fileName}
move fullPath to newFolder --create new folder and move both new files into it
move olPath to newFolder
set newFolderPath to (newFolder) as string
set newFolderPath to text 1 thru -2 of newFolderPath --remove the trailing ":"
tell current application --zip up the new folder
set qpp to quoted form of POSIX path of newFolderPath
do shell script "cd $(dirname " & qpp & ")
zip -r \"$(basename " & qpp & ").zip\" \"$(basename " & qpp & ")\""
end tell
set zipFile to newFolderPath & ".zip"
move zipFile to outputFolder --move .zip to output
delete newFolder --delete folder on desktop left from zipping
end tell
--prepare a notification email
set presetText to "Hello,
Files Uploaded:
" & fileName & ".zip
To access our FTP Server:
http://217.207.130.162:8080/WebInterface/login.html
To access our FTP server, log onto our website below:
Username:
Password:
Thanks,
Joe"
tell application "Mail" --open up prepared email
activate
set theMEssage to make new outgoing message with properties {visible:true, subject:fileName, content:presetText}
end tell
--open file containing usernames and passwords for the FTP
do shell script "open /Users/produser/Desktop/FTP_Users"
I tracked down and installed White Overprint Detector I could see what you mean. I had to use an older version as I only have CS3, and I saw the dialog it produces when you open a document. The following worked for me to get it to dismiss:
tell application "Adobe Illustrator" to activate
tell application "System Events"
tell process "Adobe Illustrator"
repeat 60 times -- wait up to 60 seconds for WOPD window to appear
try
tell window "White Overprint Detector"
keystroke return
exit repeat
end tell
on error
delay 1
end try
end repeat
end tell
end tell
Since my original post seemed too objective to understand I will revise.
With in the tell block for illustrator look for your line that opens the file. Some commands allow with and without properties. Try applying the "without dialogs" property to look something like this.
tell application id "com.adobe.Illustrator"
open file (VariableOfFilePath) without dialogs
end tell
Update:
Two work arounds I can think of. 1) Try telling system events to tell AI to open without dialogs
tell application "system events"
tell application id "com.adobe.Illustrator"
open file (VariableOfFilePath) without dialogs
end tell
end tell
Other is just add in a bit that will just okay the prompt.
try
tell application "System Events"
tell process "Finder"
click button "Continue" of window "Adobe Illustrator"
end tell
end tell
end try
Can try just having it accept the default button.
tell application "System Events"
tell process "Finder"
keystroke return
end tell
end tell
Is there a conditional command in applescript that lets the user quit the app. I turned my applescript to an app using automator. However, the script is set to run constantly until its cycled through hundreds of scripts. Is there a conditional command statement that I can use that will end the application while its running?
property MyUserName : ""
if MyUserName is "" then
display dialog "User Name:" default answer "" buttons {"Cancel", "Continue…"} default button 2
copy the result as list to {button_pressed, text_returned}
set {returnedText, returnedButton} to the result as list ---> {"some text", "OK"}
if button_pressed is "Cancel" then
beep
return
end if
if text_returned is not "" then set MyUserName to text_returned
say "Hello," using "Karen"
say (returnedText) using "karen"
else
display dialog "Stored user name: " & MyUserName buttons {"Ok"} default button 1 with icon 1
end if
say "For your information, please start the Amuse App everytime you log on... and I will speak to you at random times during your visit with me." using "Karen"
delay 20
try
repeat 105 times
set pathToMyFolderOnDesktop to ("Macintosh HD:Users:jr:Desktop:") & "Dsource:" as alias
set rnd to (random number from 1 to 105)
set rndFileName to (rnd as text) & ".scpt"
set FullPath to pathToMyFolderOnDesktop & rndFileName as text
set myScript to load script (FullPath as alias)
run script myScript
end repeat
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
return
end try
You could do something like that:
display dialog "Shall I proceed?" buttons {"Quit", "Proceed"} default button 2 giving up after 10
if button returned of result is "Quit" then tell me to quit
It's using giving up after 10 which means that that the script proceeds after 10 seconds when the user does not press any button.
To quit it from outside isn't so easy when it's an automator app because they look all the same to the system so you can't really use the application name to tell it to quit. Maybe one could use the full path, like:
tell application "/Volumes/Applications/MyAutomatorApp.app" to quit
(you can drag your automator app into the script to paste in the full path)
I am trying to script some data entry using a applescript.
I need it to paste and then tab seven times and then paste again..... 2700 times.
While I am very new to programming, I was at least able to get something working.
What I have so far:
set the clipboard to "blah"
tell application "blah"
activate
tell application "System Events"
repeat 4 times
keystroke "v" using {command down}
keystroke " "
end repeat
end tell
end tell
Now this will paste into the first form and then skip one and paste into the next one. I dont know why. So this just pastes into every other form.
Any help?
Try:
set the clipboard to "blah"
tell application "blah"
activate
tell application "System Events"
repeat 4 times
keystroke "v" using {command down}
delay 1
repeat 7 times
keystroke tab
delay 1
end repeat
end repeat
end tell
end tell
I'm trying to write an Applescript to toggle the hyperlinks in Microsoft word. (This is normally done by hitting Alt+F9).
Here's my script, but it doesn't work:
tell application "Microsoft Word"
keystroke F9 using {option down}
end tell
That just gives me an error:
"Expected end of line but found identifier"
If I use:
tell application "System Events"
tell application "Microsoft Word"
keystroke F9 using {option down}
end tell
end tell
it works but does nothing.
And if I use:
tell application "System Events"
tell application "Microsoft Word"
keystroke "Hello"
end tell
end tell
It just prints "Hello" in the applescript window. I need it to affect MS word.
No need to script simulated keyboard shortcuts here. To toggle field codes (e.g. between the form {HYPERLINK "http://www.stackoverflow.com"} and actual hyperlinks), use this script:
# toggle field codes
# same as option + F9
# tested in Microsoft® Word 2008 for Mac v 12.2.3
tell application "Microsoft Word"
set theView to active window's active pane's view
if (show field codes of theView) then
set show field codes of theView to false
else
set show field codes of theView to true
end if
end tell
Note that this will also switch other field codes, such as page numbers, off and on.
I'm trying to call a screen as a popup. The screen type is set to Modal dialog box and I'm able to call the screen, but unable to close it. Nothing happens when I click on the little cross. The next screen is set to 0.
The screen I'm calling as a popup, doesn't contain any buttons, not any hard coded ones anyway. Any ideas what I'm doing wrong?
I'd also like the screen it returns to, to be refreshed (so it loads the PBO again). How do I do that?
Here is the code:
MODULE werkende_knoppen_subscreen INPUT.
CASE ok_code.
WHEN 'X'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
You should be checking for the 'EXIT' (or, in your case for the custom close button, 'X') user command in the PAI part of your popup.
For example:
MODULE user_command_0010 INPUT.
ok = sy-ucomm.
CLEAR sy-ucomm.
CASE ok.
WHEN 'EXIT' OR 'X'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
This is a non-documented feature but in a modal dialog box (popup), the top-right button to close the popup is assigned the F12 key, so you must assign this key to a function code and process it as any other function code.
Step-by-step procedure:
1) Create the ABAP program (transaction code SE38 or SE80)
REPORT.
CALL SCREEN 100 STARTING AT 10 10 ENDING AT 60 20.
MODULE status_0100 OUTPUT. " <=== called "before output"
SET PF-STATUS '0100'. " <=== choose the GUI status
ENDMODULE.
MODULE user_command_0100 INPUT. " <=== called "after input" (after user action)
IF sy-ucomm = 'CANCEL'. " <=== the function code you chose in your GUI status
SET SCREEN 0. " <=== 0 is a special number which ends "CALL SCREEN"
ENDIF.
ENDMODULE.
Note: SET SCREEN 0 is to close the dialog box (0 means "the current dynpro sequence is ended") ; if you have a complex screen you may also use LEAVE TO SCREEN (which is equivalent to the 2 statements SET SCREEN + LEAVE SCREEN).
2) Create the screen 0100 (transaction code SE51 or double-click 0100 behind CALL SCREEN)
Screen type: modal dialog box
Flow logic:
PROCESS BEFORE OUTPUT.
MODULE status_0100.
PROCESS AFTER INPUT.
MODULE user_command_0100.
3) Create the GUI status 0100 (transaction code SE41 or double-click 0100 behind SET PF-STATUS)
Status type: dialog box
Assign the F12 key to an arbitrary function code (I chose the name CANCEL), and activate this function code (button "Function Code"):
4) Test
Run the program, you may now click the top-right button (or press F12 if you prefer) which closes the modal dialog box: