I'm working on building a small plugin in AppleScript that will find the default mail app and open that up and paste in a subject and body.
I get the error "Expected end of line but found identifier."
on run
set mailClient to getDefaultMailClient() -- store application id
tell application id mailClient
set msg to make new outgoing message with properties {subject:"subject here", visible:true}
tell msg to make new to recipient with properties {address:"email.com"}
end tell
end run
on getDefaultMailClient()
set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"
tell application "System Events"
try
value of property list item "LSHandlerRoleAll" of ¬
(first property list item of property list item "LSHandlers" of ¬
property list file prefPath whose value of property list items ¬
contains "mailto")
on error
"com.apple.mail"
end try
end tell
end getDefaultMailClient
This works fine when it opens up the program Mail on my computer but I want it to work for Entourage and any other email program for OSX.
Any help is much appreciated.
Rather than anticipate various clients and create specific code for them, you can take advantage of the abstraction the mailto: URL scheme provides - it will open a new email form in the default email client:
on newEmailForm(addr, subj, body)
do shell script "open " & ¬
quoted form of ("mailto:" & addr & "?subject=" & subj & "&body=" & body)
end newEmailForm
# Sample invocation:
my newEmailForm("somebody#some.net", "This is my subject line", "")
Note that the above uses do shell script with open rather than open location - the former conveniently automatically encodes the strings for inclusion in a URI, whereas the latter requires you to pass an already-encoded string.
You can do this by writing commands for each client.
if mailClient = "com.apple.mail" then
tell application "Mail"
--insert your code
end tell
else if mailClient = "com.something.else" then
tell application "something.else"
--insert your code
end tell
end if
Related
we have following problem. we need an extra windows popup message or baloon tip message in windows, if a mail from a specific sender arrives in outlook. are there any examples in powershell or any other programms recommend?
thanks in advance
You can use basic Outlook rules to create a desktop alert with any given condition, no need for any script or special program
If you want, the rule can also run a script and then you can do whatever you want there
From the following webpage, https://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/
Using VBA
Something like this:
Public Sub ShowMessage(Item As Outlook.MailItem)
'code
End Sub
The argument must by type MailItem or MeetingItem for the subroutine to be available in the Rules Wizard in Outlook 2007. In Outlook 2010 and 2013 (and up), PostItem also works.
Open Rules Wizard. In Outlook 2010 and 2013, it's on Outlook's Home ribbon,
Rules > Manage Rules & Alerts. Look on the Tools menu in older versions.
Open Rules Wizard
Click New Rule.
Select Apply Rule on messages I receive and click Next.
Select your conditions and click Next.
Select Run a script action (near the bottom).
The finished run a script rule
Click on a script.
Select the script
Select your script, click OK.
Click Next then finish the rule.
There are several ways to get the job done:
Create a rule in Outlook manually and assign a VBA macro which can be triggered by the rule. For example:
Public Sub TestRule(Item As Object)
If(Item.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub
Use the VBA routine for handling incoming emails. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai as Object
Set mai = Application.Session.GetItemFromID(EntryIDCollection)
If(mai.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub
I am periodically checking a website which requires me to fill a form. When I fill the form, a window pops up which includes the information I am looking for.
I was wondering if there is a way to write a program to fill the form and extract the fields that are of importance to me.
If possible,
What language is easier for doing so?
Is there any way to read one of the elements on the window that pops up? (When you right-clik on an item and select inspect element)
Could you please provide links and tutorials to implement this, so that I could write the program ASAP?
Update:
The solution using VBScript is posted. I would appreciate it if you post other solutions that could be used under OSX or Linux (Preferably OSX)
Yes we can.. one way to do it using VBS is here:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.navigate "<login url>"
WScript.Echo "Opening login page..."
WScript.Sleep 100
Do while objIE.busy
Wscript.sleep 200
Loop
WScript.Echo "Setting credentials..."
objIE.Document.getElementByID("ap_email").Value = user 'id of the input element
objIE.Document.getElementByID("ap_password").Value = pass
WScript.Echo "Email and password set!"
Call objIE.Document.Forms(0).submit
HTH!
In Dec. 2012, Mark Hunte of this stackoverflow site helped another user by providing the following AppleScript. The script creates a new email msg. and attaches a file to the end.
Could anyone here please help me? I need to have a shortened version of this script that only does one thing: attach a file named "selectedPhoto.jpg" to the end of an already open email.
That is, if I am creating a new email or replying to an email and already have the window open, I would like to run a script that simply attaches a photo to the end of that email.
I have tried taking out lines of the following script, but I can't get it to work.
I am running OS X 10.8
Can someone help?
set theAttachment1 to POSIX file "/Users/USERNAME/Desktop/Desktop--IMAGE/scooter-6.jpg"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"subject", content:"the_content" & return & return}
tell newMessage
set visible to false
set sender to "myaddress#btinternet.com"
make new to recipient at end of to recipients with properties {address:"someAddress#btinternet.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
(* change save to send to send*)
save --<<<<---------------- change save to send to send
(* change save to send to send*)
end tell
end tell
I couldn't get tell outgoing message 1 to make new attachment to work, but you could use UI scripting:
set old to the clipboard as record
set f to "/Library/Desktop Pictures/Antelope Canyon.jpg"
set the clipboard to (read (POSIX file f as alias) as JPEG picture)
activate application "Mail"
tell application "System Events" to keystroke "v" using command down
set the clipboard to old
Can anyone please tell me, how do I get the default mail client using applescript?
I found part of this code here, ran it on Snow Leopard (10.6.4), and it worked for me.
on run
set mailClient to getDefaultMailClient() -- store application id
tell application id mailClient to activate -- tell mail client to do something
end run
-- Grab id of default mail client
on getDefaultMailClient()
set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"
tell application "System Events"
try
value of property list item "LSHandlerRoleAll" of ¬
(first property list item of property list item "LSHandlers" of ¬
property list file prefPath whose value of property list items ¬
contains "mailto")
on error
"com.apple.mail"
end try
end tell
end getDefaultMailClient
Another option: VERSIONER_PERL_PREFER_32_BIT=1 perl -MMac::InternetConfig -le 'print +(GetICHelper "mailto")[1]'
there has been a discussion on this toppic in the macscripter-forum
there you find also some code examples on how test for the default mail-client
Is there a way to use defined AppleScript methods in other AppleScripts which reference the original AppleScript with something similar to import (f.e. in PHP)?
I wrote a methode to set Skype status and mood-text:
on setSkypeStatus(status, mood_text)
tell application "System Events"
set skypeRunning to count (every process whose name is "Skype")
if skypeRunning > 0 then --only set status if skype is running
tell application "Skype"
set myStatus to "SET USERSTATUS " & status
set myMood to "SET PROFILE MOOD_TEXT " & mood_text
send command myStatus script name "AppleScript"
send command myMood script name "AppleScript"
return skypeRunning
end tell
else
return skypeRunning
end if
end tell
end setSkypeStatus
now I'm searching for something like import skype_methods.scpt. Is there such a functionality. I can't something related with Google.
One way to import another script as a library is to define a property which is initialized by loading the library as a script object. You can then use the tell command to invoke the library functions.
property pSkypeLibrary : load script POSIX file "/Users/sakra/Desktop/skype_methods.scpt"
tell pSkypeLibrary
setSkypeStatus("status", "mood")
end tell
Script Foo.scpt
set theBar to "path:to:Bar.scpt" as alias
run script (theBar)
Script Bar.scpt
display dialog "Bar"
Result: A window that displays "Bar"
There is a more elegant way of doing this. You can save your skype_methods.scpt file inside a Script Libraries folder on your computer.
Depending on how you want to define the availability of this library, you use a different folder.
Place the skype_methods.scpt file inside the /Library/Script Libraries folder to make it available for all users on the computer.
Place it in the ~/Library/Script Libraries folder to make it available for a specific user only.
You can then use all the handlers in that library as follows:
property Skype : script "skype_methods"
Skype's setSkypeStatus("status","mood")
This prevents the need of numerous tell blocks when using handlers from different libraries.
You can follow this repo https://github.com/abbeycode/AppleScripts which organises its scripts into libraries
Here is an example https://github.com/abbeycode/AppleScripts/blob/master/Scripts/Download%20Chase%20Activity.applescript
property LibLoader : load script file ((path to scripts folder from user domain as text) & "Libraries:Library Loader.scpt")
property TransmissionLib : LibLoader's loadScript("Libraries:Transmission.applescript")
property GrowlLib : LibLoader's loadScript("Libraries:Growl.applescript")
property SafariLib : LibLoader's loadScript("Libraries:Safari.applescript")
property DatesLib : LibLoader's loadScript("Libraries:Dates.applescript")