Is there a way to create a script that will change the preferences of iChat to run the script when a message is received?
In other words, I want to make a script to change the iChat preferences to enable the "Message Received.applescript" i have created. Wow, this is confusing. Let me simply this.
I want a script that does this:
Activate iChat
Open iChat Preferences
Move to "Alerts" tab
select event "Message Received"
turn on "Run applescript"
select a certain script from the script folder called "Message Receive.applescript"
please help?
You just need to edit iChat's plist file. defaults is a bit awkward for nested values so use System Events instead:
tell application "System Events"
set EventActions to property list item "EventActions" of property list file ((path to preferences folder from user domain as text) & "com.apple.iChat.plist")
repeat with e in {property list item "MessageNotification" of EventActions, property list item "SubsequentMessage" of EventActions}
make new property list item at end of e with properties {name:"RunAppleScript", value:true}
make new property list item at end of e with properties {name:"iChatAppleScriptsKey", value:{"~/Library/Scripts/iChat/Message Received.scpt"}}
end repeat
end tell
This will attach "Message Received.scpt" to both initial text invitations and subsequent messages - you could simplify it if you only wanted it for subsequent messages. Also note you may need to relaunch iChat for the change to take effect.
Related
I have created an Apple Automator service that
receives PDFs
encrypts them
copies the encrypted PDF to a destination folder
renames the encrypted PDF
These are all commands from the Automator. However, the copying as an Automator command can only copy to a pre-defined folder.
I would like to control this part by an AppleScript which reads out the user name and selects a folder accordingly:
on run {input, parameters}
set user_script to "echo $USER"
set username to do shell script user_script
if username = "A" then
set standardpfad to "/Users/" & username & "/whatever"
else if username = "B" then
set standardpfad to "/Users/" & username & "/foo"
else
display dialog "I don't know this user!" with title "ERROR" buttons {"OK"} default button "OK"
return
end if
#actual copying
end run
Unfortunately, I don't know how to handle the input in way that it resembles the "Copy Finder object" command in Automator. Can anyone please help me?
Thank you!
Edit:
Automator screenshot
Going by your original script, which seems to want to move all the files to the user's home folder, you can accomplish what you want using an automator variable. First, go to the upper left of the Automator window, click on the tab button that says 'Variables', then click on the 'Locations' item. Look for the item that says 'Home' (I believe that's 'Privat' on your machine's language):
This provides to a path to the user's home folder, for whichever user is running the workflow (system and machine independent). Drag this variable over to the Copy Finder Items (Finder-objekte kopieren) action, and drop it on the 'To:' ('Nach:') pull-down menu. It should look like this:
That should do the trick.
There are an assortment of system defined user paths you can choose from. You can also define a custom one using the special 'Text' variable (under 'Text & Data'), typing a path in standard unix notation where the tilde ('~') represents the user's home folder: e.g., ~/path/to/Custom Folder/.
If you're doing something more complicated and really need to use a Run AppleScript action, all you need to know is that the list of files is passed into the action in the input variable as a list of aliases, and whatever you return (should be a list of aliases or posix paths), will be passed on to the next action. For example:
on run {input, parameters}
set output to {}
repeat with this_item in input
set new_item to this_item -- ... obviously you'd do something other than just copy
copy new_item to end of output
end repeat
return output
end run
But it doesn't seem like you need to do that here; the special Automator variables should get you where you're going.
EDIT
Per comments, here's a revised version of the workflow...
Add the following actions to the workflow given in the question in place of the "Copy Finder Objects" action. Note that the second and sixth actions are set to ignore input from the previous action. These actions do the following:
Save the list of files to be copied to a storage variable called 'FileToCopy'; pass no data on
Get the path to the user's home folder; pass it to the next action
Get the user's 'user name'; pass the home folder and user name to the next action as a list
Run an AppleScript that constructs a unix path string from the input list; pass the completed path string on to the next action
Save the path string into a variable called 'DestinationFolder'; pass no data on
Retrieves the list of files to copy we saved in step #1; pass it on to the next action
Copy the files to the selected folder, using the 'DestinationFolder' variable we saved in step #5; pass these on to the Rename Finder Items action (not shown here)
Give it a go, and let me know how it works.
Please note: The site is not letting me post this question unless I incorrectly format it i.e. the two middle sections of "code" which aren't actually code. I've done my best to edit it, to fix it, and I apologise if the formatting is poor.
I’ve found and adjusted two scripts, which run, individually. This is my first AppleScript project, and I’d like help joining them together to MAKE ONE SCRIPT.
I want Script 2 to use the result from Script 1.
e.g. set menuItems to (Script 1 Result names)
I made a dummy testGroup in my Contacts. The Pop-Up Menu only needs the names. I will use the corresponding email addresses later, in another script.
I hope this is clear enough. Thanks in advance for your help.
Script 1
--returns Contacts testGroup’s names and email addresses
set myList to ""
tell application "Contacts" to repeat with p in people in group "testGroup"
if emails of p is {} then
set e to ""
else
set e to value of email 1 of p
end if
set myList to myList & name of p
end repeat
Script 1 Result needs parsing...
"Joe BloggsMolly MousePeter Pan"
to this...
{"Joe Bloggs", "Molly Mouse", "Peter Pan"}
so I can use it in Script 2 menuItems below.
Script 2 MUST use names from Script 1 Result, like this
-- Make Pop-Up Menu in Numbers spreadsheet which is already open.
set menuItems to {"Joe Bloggs", "Molly Mouse", "Peter Pan"}
tell application "Numbers"
activate
tell the first table of the active sheet of document 1
tell cell "A3"
set value to item 1 of menuItems
set the format to pop up menu
end tell
end tell
end tell
tell application "System Events"
tell application process "Numbers"
set frontmost to true
tell window 1
click radio button "Cell" of radio group 1
repeat with i from 2 to (count menuItems)
click button 1 of group 1 of scroll area -1
keystroke (item i of menuItems)
end repeat
end tell
end tell
end tell
The first script is going through the items of a list list to create a string, while the second script is just wanting the list. Since the Contacts application will give you a list of names, the first script isn't needed at all - the menuItems of the second script can just be set with:
tell application "Contacts" to set menuItems to the name of people in group "testGroup"
I have a registered domain, and I use hushmail as a mail provider. I'd like to send emails from Mail.app as if they were sent from my domain. The Hushmail SMTP server does not allow me to use a different "from" address than my account name, for security reasons (spam).
I found a way to have Apple mail fill the reply-to mail with a default all the time, here: http://email.about.com/od/macosxmailtips/qt/etalwaysreplyto.htm but that's too drastic for me, as I have multiple mail accounts in my mail client.
In Mail.app, I can set the "Reply to" field manually, but there is no setting in Mail.app to have that automatically filled based on the mailbox I select.
So far, I have an AppleScript which is able to create a reply on the selected mail:
tell application "Mail"
set theSelection to selection
if theSelection is {} then return
activate
repeat with thisMessage in theSelection
set theOutgoingMessage to reply thisMessage with opening window
# Wait for Mail.app to create the reply window
repeat until exists (window 1 whose name = "Re: " & subject of thisMessage)
end repeat
delay 0.1
#
# Here I want to set the reply-to address here based on the
# selected mailbox, or the "from" address of
# the current mail.
#
#
# The I need to restore the cursor to the body of the mail
# (if cursor was moved)
#
end repeat
end tell
I've looked in the AppleScript Dictionary (File -> Open Dictionary -> Mail.app -> Message -> message -> reply to), and this seems to be a property I should be able to set, but when I do something like:
tell theOutgoingMessage
make new recipient at end of reply to with properties {address:"myreplyto#example.com"}
An error pops up saying "Mail got an error: Can't get reply to of outgoing message id 65."
I also tried
tell theOutgoingMessage
set reply to to "myreplyto#example.com"
But that pops up an error saying "Mail got an error: Can’t set reply to of outgoing message id 69 to "myreplyto#example.com".
How can I set the reply-to property of the reply mail I just created?
As I mentioned in the comments to your post, you can't set the reply-to address programmatically because it's a read-only property. Therefore you need to ui script this solution.
The problem with ui scripting is that it's not an exact science. If Apple changes the positioning of the ui elements then your script will stop working. For example, I have Mail.app v6.5 and the reply-to field can be referenced using "text field 1 of scroll area 1 of window 1". In other versions of Mail.app that could be different (and probably is).
Anyway, in v6.5 of Mail.app this will do what you want using ui scripting.
tell application "Mail"
set theSelection to selection
if theSelection is {} then return
activate
repeat with thisMessage in theSelection
set replyToAddress to item 1 of (get email addresses of account of mailbox of thisMessage)
set replyToWindowName to subject of thisMessage
if replyToWindowName does not start with "Re:" then set replyToWindowName to "Re: " & replyToWindowName
-- open the reply message
set theOutgoingMessage to reply thisMessage with opening window
-- Wait for Mail.app to create the reply window
repeat until exists (window 1 whose name is replyToWindowName)
delay 0.2
end repeat
-- make sure the reply-to field is showing
my openReplyToField()
-- set the reply-to address here based on the selected mailbox
my setValueOfReplyToField(replyToAddress)
end repeat
end tell
on openReplyToField()
tell application "System Events"
tell process "Mail"
-- figure out if the reply-to text field is visible
set staticText to value of every static text of window 1
if staticText contains "Reply To:" then return
-- the reply-to field is not visible so we click the menu item
set viewMenu to menu 1 of menu bar item "View" of menu bar 1
set replyToMenuItem to first menu item of viewMenu whose name contains "Reply-To"
click replyToMenuItem
end tell
end tell
end openReplyToField
on setValueOfReplyToField(theValue)
tell application "System Events"
tell process "Mail"
set replyToField to text field 1 of scroll area 1 of window 1
set value of replyToField to theValue
end tell
end tell
end setValueOfReplyToField
Try if this works:
make new recipient at end of to recipients with properties {address:"myreplyto#example.com"}
I'm building an Automator workflow that parses a Dropbox "gallery" page containing Quicktime video files, and automatically builds "direct-download" links for each of the files. In the end, I want all the links to be generated into the body of a Mail.app message.
Basically, everything works as expected, except for the part where the new links are sent to a new Mail.app message. My problem is that the links are sent to the body of the message without newlines, so they all get concatenated into a single line, like this:
https://dl.dropbox.com/u/149705/stackexchange/20121209/stackexchange_automator_prob2.png
(Mail.app seems to be wrapping the concatenated string on the question-marks)
The oddest thing about this is that if I use a "Copy to Clipboard" action at the end of the workflow (instead of my send-to-Mail Applescript), I get totally different results when I paste the same clipboard contents into TextEdit vs. BBEdit.
The links seem to paste into TextEdit properly. However, the same clipboard, pasted into a plaintext BBEdit document, yields only the first link:
https://dl.dropbox.com/u/149705/stackexchange/20121209/stackexchange_automator_prob5.jpg
What could be causing these 3 entirely different behaviors from the exact same results of the "Get Link URLs" action?
The reason you get that result is it the links start out as a List of strings but are being sent to mail.app as a single string.
You do not need to do anything fancy to fix this just put a return after the link.
I would just use this a single 'Run applescript' Action to do the whole job.
The script gathers only the file DL links. Adds a return on the end and send them to Mail.app.
No other formatting required
on run {input, parameters}
set db_tag to "dl-web.dropbox.com/get"
set myLinks to {}
tell application "Safari"
set thelinkCount to do JavaScript "document.links.length " in document 1
repeat with i from 1 to thelinkCount
set this_link to (do JavaScript "document.links[" & i & "].href" in document 1) as string
if this_link contains db_tag then
--add the link with a carriage return on the end.
copy this_link & return to end of myLinks
end if
end repeat
end tell
tell application "Mail"
activate
make new outgoing message with properties {visible:true, content:"" & myLinks}
end tell
end run
Get rid of all of the other actions and update myPage with your gallery URL.
on run
set myPage to "https://www.dropbox.com/sh/aaaaaaaaaaaaaaa/aaaaaaaaaa"
set myLinks to do shell script "curl " & quoted form of myPage & " | grep -Eo 'https://www.dropbox.com/sh/[^/]*/[^/\"]*/[^\"]*' | sed s'/https:\\/\\/www.dropbox.com\\(.*\\)/https:\\/\\/dl.dropbox.com\\1?dl=1/g'"
tell application "Mail"
activate
make new outgoing message with properties {visible:true, content:"" & myLinks}
end tell
end run
Each application is different, it understand or don't understand the output's format.
Regarding your AppleScript action:
input is an AppleScript list, the coercion from a empty string "" do a single line, because the delimiters is set to "" by default.
To get the desired result, set the delimiters to return or linefeed, like this.
on run {input}
set {oTID, text item delimiters} to {text item delimiters, linefeed}
set tContent to input as text
set text item delimiters to oTID
tell application "Mail"
activate
make new outgoing message with properties {visible:true, content:tContent}
end tell
return input
end run
While trying to make an automator action that opens multiple tabs from selected text as input I ran into an applescript issue I wasn't able to solve for awhile. This includes the answer and I'm posting this here because I just wasn't able to find documentation on how to handle data in "input" for a receives selected "text" in "any application" automator action, everything is for files which comes in as a list already.
When putting an applescript action in, you get:
on run {input, parameters}
the problem here is that input isn't in a list format and trying to do anything with it breaks the script or throws an error. ie I can't do:
repeat with URL in input
set this_URL to URL
So how can I treat a list of selected text as a list of items?
the solution is first treat input as a string then break apart every paragraph.
on run {input, parameters}
set inputText to input as string
set URL_list to every paragraph of inputText
Without treating input "as string" first before doing "every paragraph of" it won't work.
Here's the end working script, replace the "some_url" with your own. You'll be able to select several lines of text in an editor and treat each one as a parameter to your fixed url opening each in a new safari tab. This could be expanded upon by having each line be delimited for multiple params on the url.
on run {input, parameters}
set inputText to input as string
set URL_list to every paragraph of inputText
tell application "Safari"
activate
repeat with URL in URL_list
set this_URL to URL
# extra processing of URL could be done here for multiple params
my new_tab()
set tab_URL to "http://some_url.com?data=" & this_URL
set the URL of document 1 to tab_URL
end repeat
end tell
return input
end run
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Tab" of ¬
menu "File" of menu bar 1
end tell
end tell
end new_tab
As an example say you had the list and had a service of the above using "http://stackoverflow.com/posts/" & this_URL
6318162
6318163
6318164
you could now select them click services and choose your "StackOverflow - view questions" service and it'll append and open each one in a new safari tab. In my case I needed to verify multiple dns entries in our server as still valid and do a bunch of whois lookups.
I was looking for the same thing, just for files as input from Automator to AppleScript.
ddowns's trick didn't work for that, but ended up using this, hope it's helpful for someone looking for solving the same issue I ran into:
on run {input, parameters}
-- create empty list
set selectedFiles to {}
-- add each list item to the empty list
repeat with i in input
copy (POSIX path of i) to end of selectedFiles
end repeat
-- show each item (just for testing purposes of course)
repeat with currentFile in selectedFiles
display dialog currentFile as text
end repeat
end run
As Hanzaplastique says, for AppleScript within Automator, you don't need the Safari AppleScript because there's an Action for that. I use the following Actions:
Extract URLs from Text (actually the 'Extract Data from Text' Action)
Run AppleScript
Display Webpages
I use it as a Workflow added to the Services menu so that I can right-click on selected text in an email and open multiple URLs in Safari tabs.
In particular, I get Server / WordPress updates in an email but the URLs are just the top level of the domains and I want to jump to the plugins page of WordPress. So, my AppleScript (with thanks to Hanzaplastique) is:
on run {input, parameters}
set AppleScript's text item delimiters to {return & linefeed, return, linefeed, character id 8233, character id 8232}
-- create empty list
set selectedFiles to {}
-- add each list item to the empty list
repeat with i in input
set AppleScript's text item delimiters to {" "}
set i to i & "/wp-admin/plugins.php"
copy i to end of selectedFiles
end repeat
return selectedFiles
end run
I found I needed the 'return selectedFiles'. The always mysterious (to me) text delimiters may not be necessary and come from the previous version which only pulled out a single URL.