AppleScript - How to Access Mail Directory? - applescript

I am trying to access folder in my mail using apple script. but did not succeed.
My folder Name is : BLABLABLA , it resides under Apple Mail .
I think that it should be :
set myDir to mailbox "BLABLABLA"
this does not work, any suggestions ?

This will retrieve the account mailbox
tell application "Mail"
set AccountNames to name of accounts
choose from list AccountNames with prompt "Select the email account" ¬
without multiple selections allowed
set AccountName to result as string
set MailboxesListV to mailboxes of account AccountName
end tell
Which is what I think you want. (Notice that the result is a list.)
I hope it helps.

Related

AppleScript executes both If and Else, but only on a network user, not on a local admin

I'm trying to modify a local property file for an application, for each of our Network users, who each have local User folders on each client computer. The property file is stored in the local user folder, that I want to do the following with, so this happens on login rather than having to do this manually on a whole lot of users:
Check if it has the relevant modifier string already
If it does not, append the string to the text configuration file
The following code works perfectly when executed from the admin account: It adds the string if it isn't already there, and if it is, then it displays the Dialog window (That I just have there to debug it)
However, the moment I log on with a Local Network Account, it BOTH displays the Dialog Window AND adds appends the string to the configuration file, and keeps adding a new one for every login. It applies these to the correct file, so the file path is still pointing at the right config file.
I don't understand why the same script would behave like this?
set userName to short user name of (system info)
set JournalProps to "/Users/" & userName & "/NameOfTheConfigFileHere"
close access (open for access JournalProps)
set FontSize to "name_fontsize=18"
set TheFileContents to paragraphs of (read JournalProps)
if FontSize is in TheFileContents then
set DisplayText to "Fontsize already set"
display dialog DisplayText
else
write linefeed & "name_fontsize=18" & linefeed to JournalProps as "utf8" starting at eof
end if

Getting Mac Hazel to e-mail .lnk, doc, and .xls files to my evernote account

i'm trying to automate and simplify my life. I'm new to hazel and apple scripts..
I have a lot of documents and i pull a lot of things of the web. i simply drag the link to my desktop where it makes a .lnk file.
i want to create a hazel + apple script that will look for these .lnk files and send an email with the link file attached to my evernote email address.
Any suggestions would be appreciated.
In Hazel Create a new rule.
If all ..
1, Extension - is - ink
Do the following:
2, Run AppleScript - embedded script.
Click the info icon to edit the script. Paste this script into it. With the correct email addresses, subject, content set.
set theAttachment1 to (POSIX path of theFile)
set subject_ to "subject"
set the_content to "the_content"
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 "my1#mac.com"
make new to recipient at end of to recipients with properties {address:"their#mac.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
(* change save to send to send*)
send --<<<<---------------- change save to send to send or send to save to save to drafts
(* change save to send to send*)
end tell
end tell
3, Add a second action to move the file to a folder. If not you may keep getting the same files sent over and over again.

How to find the default mail client on Mac OS X?

I've an application which gives Images as outputs and those outputs are to be opened in a mail client's new message [as an attachment].
On Mac OS X, Apple mail is the default mail client. So what I did was, wrote an automator workflow and opened the output in Mail.app using 'Open Finder Items' action.
Here is my problem:
If user has configured the 'Microsoft Entourage' or 'ThunderBird' or any other mail clients as their default mail client then my automator action cannot open the output in their configured mailing app.
I got some idea to find and launch the default mailing application in this link.
How do I get the default mail client using applescript?
can anyone help me how can I attach my output images to a new mail message of the launched mail client?
For the record, the accepted answer in the linked question was something like this:
tell application "System Events"
try
value of property list item "LSHandlerRoleAll" of (property list item 1 of property list item "LSHandlers" of property list file (path to preferences as text) & "com.apple.LaunchServices.plist" where value of property list items contains "mailto")
on error
"com.apple.mail"
end try
end tell
You could also use MMac::InternetConfig:
VERSIONER_PERL_PREFER_32_BIT=1 perl -MMac::InternetConfig -le 'print +(GetICHelper "mailto")[1]'
or DefaultApplication:
$ ~/bin/DefaultApplication -url mailto:
/Applications/Mail.app

Get network address of a file in AppleScript

We are a network of Mac computers. I would like to send email addresses to colleagues with links to files on network locations. I made the following AppleScript:
tell application "Finder"
set uuu to URL of the first item of (get the selection)
set the clipboard to uuu
end tell
which puts the URL of the currently selected file into the clipboard, which can then be pasted into the message (using the Add Link menu item), providing, for example:
file://localhost/Volumes/Commerciale/Clienti/
Unfortunately these links do not work. If I select Go To Folder from the menu item, I can get to the folder using an afp:// type URL.
Is there any way to get this via AppleScript like I do with URL above?
I have solved with this script:
on urlToPOSIXPath(theURL)
return do shell script "python -c \"import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])\" " & quoted form of theURL
end urlToPOSIXPath
tell application "Finder"
set uuu to URL of the first item of (get the selection)
set pp to my urlToPOSIXPath(uuu)
set the clipboard to "file://" & pp
end tell
Are the volumes already mounted on the email recipients' Mac? Netlink makes a URL that is clickable in Mail. I don't have an AFP share here to test this:
tell application "Finder" to set netlink to URL of (get selection as alias)
Not "automagically" as far as I know. The URL and POSIX path properties only returns the shared directory and not the volume itself. If you use the URL given to you by Applescript, only Applescript can still resolve it. (I get the impression the OS or Applescript is just iterating down the mounted volumes finding the file) You'll need to manipulate the path string to get the format you need.
here is an expanded version of markratledge's post
tell application "Finder" to set netlink to URL of (get selection as alias)
tell application "Mail"
launch
set newMessage to make new outgoing message with properties {subject:"network link", content:netlink, visible:true}
-- Add in code for recipient, etc, etc
--send newMessage
end tell
but that still doesn't seem to work lol

How to get the contact online status of Skype friends via Applescript

is there a way to get the online status of each Skype contact via Applescript?
So far I only managed to get the group of online users. However, I need also the corresponding online status.
Thnaks for your help!
Cheers
Julian
set groupType to send command "GET GROUP " & group & " TYPE" script name "getType"
if groupType contains "ONLINE" then
set onlineFriends to send command "GET GROUP " & group & " USERS" script name "getType"
Okay, its quite easy... sometimes it helps to take a break ;-)
tell application "Skype"
set result to send command "GET USER <userName> ONLINESTATUS" script name "getType"
end tell
Cheers
Julian

Resources