is it possible that when a new email message is received to run applescript to copy sender’s email address to clipboard and paste it to next empty cell in column e in numbers, I've been trying with this, but it doesn't select the first message
thanks in advance :)
property workFlowPath : quoted form of ("/Users/pl 1/Library/Application Scripts/com.apple.mail/accepted.workflow") --CHANGE THIS TO YOUR FULL WORKFLOW FILE PATH example "/Users/pl 1/Library/Application Scripts/com.apple.mail/accepted.workflow"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
(*Get the email Subject *)
set input_Argument to subject of eachMessage
(*Run subroutine for workflow *)
my runAutomator(input_Argument)
end repeat
end perform mail action with messages
end using terms from
(*Workflow Subroutine *)
on runAutomator(input_Argument)
(*Path to workflow *)
(*Setup and Run the unix command *)
set command to "/usr/bin/automator -i " & quoted form of input_Argument & space & workFlowPath
do shell script command
end runAutomator
on run {input, parameters}
tell application "Numbers"
tell application "Finder"
set theFile to POSIX file “/Users/pl 1/Google Drive/Publication Submission Tracker2.numbers"
open theFile
end tell
end tell
return input
end run
________pause for 5 seconds______
tell application "Mail"
reopen
activate
set theSenderList to {}
set theMessages to the first message of message viewer 0
repeat with aMessage in theMessages
set oneAddress to extract address from sender of aMessage
set end of theSenderList to oneAddress
end repeat
set the clipboard to (theSenderList as string)
end tell
return
end run
________pause for 5 seconds______
tell application "Numbers"
reopen
activate
tell application "System Events" to tell process "Numbers"
set currentCell to "e2"
keystroke "v" using {command down}
end tell
end tell
end run
It is best not to use UI scripting here. You want to set this up as a trigger in mail.app. Your script can pull the sender email address and then programmatically add it to the first empty cell in a row. Here's a script to get you started:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application id "com.apple.iWork.Numbers"
activate
-- can also tell Numbers to open a specific document
end tell
tell application "Mail"
repeat with eachMessage in theMessages
set fromAddress to extract address from reply to of eachMessage
tell application id "com.apple.iWork.Numbers"
tell document 1
tell the active sheet
tell table 1
tell column "E" -- change to preferred column
-- find the last empty row in this column
set r to (address of row of first cell whose value is missing value)
set value of cell r to fromAddress
set r to r + 1
end tell
end tell
end tell
end tell
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
Edit: I edited the script to check for the next cell with a 'missing value' (instead of the cell value > 0) so that it can handle numbers and dates, such as:
set value of cell r to date "12/5/15"
Related
I have written - with the help of various sources of course -, this script to redirect mail in bulk: it redirects all mail selected in the mail app. There seems to be nothing special going on.
tell application "Mail"
set AppleScript's text item delimiters to ""
set theRedirectRecipient to "redirectmail#mail.mail"
set theRedirectSender to "Sender"
set theMessages to the selection
repeat with thisMessage in theMessages
tell application "Mail"
set theRedirectedEmail to redirect thisMessage with opening window
tell theRedirectedEmail
if subject of thisMessage is "" then
set subject of theRedirectedEmail to "Mails zonder subject"
end if
make new to recipient at beginning of to recipients with properties {address:theRedirectRecipient}
#delete bcc recipients
#delete cc recipients
end tell
#delay 2
#send theRedirectedEmail
end tell
end repeat
end tell
As above, the script runs fine: it creates the redirect mail, and if I press the send button, it works like I need it to.
But there are 3 lines commented out that do not work. The delete lines and the send line. I'm not really sure I care about the delete ones, but I have included them in case someone can see a pattern.
Uncommenting one of those lines gives me this error:
error "Mail got an error: Can’t get every cc recipient of outgoing
message id 18." number -1728 from every cc recipient of outgoing
message id 18
Again, this does create a message-window that I can send successfully if done by hand.
Uncommenting the 'send' line introduces the following error:
error "Mail got an error: outgoing message id 19 doesn’t understand
the “send” message." number -1708 from outgoing message id 19
So what I have concluded is that the created message doesn't behave as a message 'should'. I have seen this thread about an 'outgoing message' that seems to display this behaviour.
What is going on with this message called theRedirectEmail? How can I send messages to this object, like delete and send?
I noticed this same issue. Here's the workaround I came up with. In some ways, it's actually easier:
tell application "Mail"
set AppleScript's text item delimiters to ""
set theRedirectRecipient to "redirectmail#mail.mail"
set theRedirectSender to "Sender"
set theMessages to the selection
repeat with thisMessage in theMessages
redirect thisMessage with opening window
tell application "System Events"
tell application process "Mail"
tell window 1
--wait for mail message to appear before continuing
repeat while not (text field "To:" exists)
end repeat
set value of text field "To:" to theRedirectRecipient
set value of text field "Cc:" to ""
if text field "Bcc:" exists then
set value of text field "Bcc:" to ""
end if
if value of text field "Subject:" is equal to "" then
set value of text field "Subject:" to "Mails zonder subject"
end if
end tell
tell application "Mail" to activate
click menu item "Send" of menu 1 of menu bar item "Message" of menu bar 1
end tell
end tell
end repeat
end tell
You have to tell Mail to activate, because Mail doesn't allow the sending of email when it's in the background, probably to prevent evil-doers from spamming your entire contacts list in the background, without your knowledge, using AppleScript. This may be related to the strange behavior of mail regarding outgoing messages too, though I can't be sure...
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)
Okay, I need to add some emails to my Daylite tasks automatically based on certain criteria, so I set up a Mail.app rule and an AppleScript to accomplish this. There's only one problem: when the AppleScript gets the content of the message, it adds an 'a' at the end (and makes a beep as well, letting me know it tried some keystroke that apparently wasn't allowed).
Here's what the AppleScript looks like:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
try
set this_subject to subject of eachMessage
set this_body to content of eachMessage
if this_subject is "" then error
on error
set this_subject to "No subject."
end try
activate application "Daylite"
tell application "System Events"
keystroke "t" using {command down, shift down}
keystroke this_subject
keystroke tab
keystroke this_body
keystroke "s" using command down
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
This results in me getting a new task in Daylite, where the task title is the email Subject, and is displayed correctly, but the attached note, which is the email's body, is not displayed correctly.
So, if I receive an email that matches my rule, and the email is:
From: Hypothetical Wife
Subject: Don't forget to take out the trash!
Body: If you forget one more time, I'm filing for a divorce.
That ends up with a task that looks like this:
☐ Don't forget to take out the trash!
If you forget one more time, I'm filing for a divorce.a
… making my hypothetical wife in this scenario sound like a barely literate Canadian. (Plus there's an system alert sound, letting me know it apparently tried to type something that's not allowed.)
If the body has multiple lines of text, it also annoyingly removes the line-breaks.
I know I could set it to:
set the clipboard to this_body
and then replace
keystroke this_body
with
keystroke "v" using command down
…but that's a really inelegant solution and I don't want to replace whatever's in my clipboard every time the rule runs.
What am I doing wrong here? I've tested this in TextEdit as well, and the same problem occurs there too, so it's not a Daylite problem. I've also tried appending "as Unicode text" or "as string" or "as «class UTF8»" to the end of the "set this_body…" line, but none of those fixed the problem either.
Please, explain it to me like I'm a complete idiot because, as a complete idiot, that's the only way I'll understand you. Thanks.
One of the basic mistakes many people make is telling an application to do things that the application does not know how to do. You should only tell an application to do things that you can find in its applescript dictionary because that's really all the application knows how to do... besides some basic general purpose applescript stuff like performing a repeat loop.
You have fallen into this trap. You are telling Mail to tell Daylight and System Events to do things because all of that code is inside the "tell application Mail" block of code. This type of error often leads to problems that are very difficult to track down.
As such, my first suggestion would be to stop telling Mail to do unnecessary things. Here's how I would write your code to separate the different application commands from each other.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail"
set this_subject to subject of eachMessage
set this_body to content of eachMessage
end tell
if this_subject is "" then set this_subject to "No subject."
activate application "Daylite"
delay 0.2
tell application "System Events"
tell process "Daylite"
keystroke "t" using {command down, shift down}
delay 0.2
keystroke this_subject
delay 0.2
keystroke tab
delay 0.2
keystroke this_body
delay 0.2
keystroke "s" using command down
end tell
end tell
end repeat
end perform mail action with messages
end using terms from
You'll also notice I added a small delay between some of your code. Sometimes the code runs more quickly than the computer interface can handle, so that too may be a source of your error. You can also try increasing the length of the delay if needed (any delay over 1 second is overkill and shouldn't be necessary).
If these changes and a longer delay don't work then a simple solution would be to check if the text ends with "a" and just remove it. Something like this between the keystroke tab and keystroke this_body lines...
if this_body ends with "a" then set this_body to text 1 thru -2 of this_body
Good luck!
EDIT: the "keystroke" process doesn't seem to like the return characters from the email. I believe that's what causing the noise... when it hits a return character it beeps. Anyway, you can try something like this. Just open a blank TextEdit document and select an email in Mail and run the code in AppleScript Editor. You can incorporate this idea in your Daylight script.
tell application "Mail"
set eachMessage to item 1 of (get selection)
set this_subject to subject of eachMessage
set this_body to content of eachMessage
end tell
set bodyList to paragraphs of this_body
activate application "TextEdit"
tell application "System Events"
tell process "TextEdit"
repeat with i from 1 to count of bodyList
keystroke (item i of bodyList)
keystroke return
end repeat
end tell
end tell
I have simple service I'm using to import Evernote files:
on run {input}
tell application "Evernote"
repeat with x in input
try
create note from file x
on error error_message number error_number
display alert "Send to Evernote Failed" message "Error: " & error_message & "" & "Error Number: " & error_number as warning
end try
end repeat
end tell
end run
I would like to "create note from file x created d", where d is a date/time that matches that of the original file - but I don't know how to get the date/time (either created or modified) of the original file in a format that is an applescript date.
I appreciate the help!
I don´t know where you´re getting your "input" from, but assuming that with "files" you literally mean files int the Finder, calling Finder to get info on the file in "input" should work like this:
tell application "Finder" to set input to selection
repeat with x in input
tell application "Finder" to set creationDate to creation date of x
end repeat