Jump to content

Mail AppleScript to take Mailbox Offline - A simple quotation marks issue?


Recommended Posts

Apologies for what is a pretty basic question for most people in this forum, but does anybody know how to click a menu item that contains quotation marks?

 

More specifically, in the Mail app, I would like to take one of my mailboxes offline (as opposed to taking them all offline). However, the menu items include quotation marks around the name of each mailbox. For example, from the menu's hierarchy, the menu might look something like the following:

 

  • Mailbox
    • Online Status
      • Take "GMAIL" Offline
      • Take "AOL" Offline
      • Take "Hotmail" Offline
      • Take "Prodigy" Offline

 

Under this setup, what should my applescript look like if I wanted to click the GMAIL option? I've tried the following code below, but it doesn't work.

if application "Mail" is running then
	activate application "Mail"
	tell application "System Events"
		tell process "Mail"
			click menu item "Take \"GMAIL\" Offline" of menu 1 of menu item "Online Status" of menu 1 of menu bar item "Mailbox" of menu bar 1
		end tell
	end tell
else
	display notification "To take a mailbox offline, Mail must be open." with title "Mail - Not Open"
end if

 

I suspect I screwed up how to deal with quotation marks in the string, but I can't seem to figure it out. I've tried adding more slashes and moving them around, but I haven't had any luck. 

 

I'm a newbie, so thanks for any help you can lend!!

Link to comment

@deanishe Thanks for taking a stab at it!

 

Unfortunately, I didn't have any luck with the following: 

if application "Mail" is running then
	activate application "Mail"
	tell application "System Events"
		tell process "Mail"
			click menu item "Take " & quote & "GMAIL" & quote & " Offline" of menu 1 of menu item "Online Status" of menu 1 of menu bar item "Mailbox" of menu bar 1
		end tell
	end tell
else
	display notification "To take a mailbox offline, Mail must be open." with title "Mail - Not Open"
end if

 

Any other ideas?

 

I've been able to get the closet with the following:

set inString to "GMAIL"
set myString to "Take " & quoted form of inString & " Offline"

if application "Mail" is running then
	activate application "Mail"
	tell application "System Events"
		tell process "Mail"
			click menu item myString of menu 1 of menu item "Online Status" of menu 1 of menu bar item "Mailbox" of menu bar 1
		end tell
	end tell
else
	display notification "To take a mailbox offline, Mail must be open." with title "Mail - Not Open"
end if

 

However, I still get an error indicating that the mailbox is not in double quotes (testing with Script Editor):

Error.jpg.e371d45a33ca0bf87e50d66221a51b01.jpg

 

This is driving me crazy! Thanks for any help you can lend.

 

Edited by Jasondm007
Link to comment

Apologies if I'm being dense here, but are you guys saying that I should be using smart quotes in the script (i.e., double smart/curly quotes)? If so, where (and, with which iteration of the script above)?

 

At the moment, I definitely don't use smart quotes in it. I've made the mistake of including smart quotes in a script before, and have turned this feature off in my keyboard settings (System Preferences / Keyboard / Text - unchecked "Use smart quotes and dashes").

 

Thanks for all of your help! 

Link to comment

I’m saying that the Mail menu item probably uses smart quotes, so you need to use them in the menu name, or it won’t match:

 

click menu item “Take “GMAIL” Offline”

 

where the inner pair of quotes are smart quotes.

 

Similarly, any menu items ending with dot dot dot don’t end with three dots, but with one ellipsis.

 

 

Link to comment

@deanishe Thanks for the clarification.

 

Assuming those are smart/curly double quotes around the mailbox's name - which looks correct to me - how do you create those in an applescript? 

 

Also, just to be clear, there are no ellipses or dots for that matter in the menu. The menu looks just like the hierarchy in my first post (though, obviously the names of mailboxes are not GMAIL, AOL, Hotmail, and Prodigy).

 

Thanks again!

Link to comment

@deanishe Thanks! I was able to get it working with the original script by removing the /s and making sure I used smart quotes around the mailbox's name. In short, it works like a charm now!! I can't thank you enough. 

 

For other newbies, this is the final script that I use in an Alfred workflow to take a specific mailbox offline in Mail (making sure to substitute GMAIL with the name of your mailbox):

on alfred_script(q)
if application "Mail" is running then
	activate application "Mail"
	tell application "System Events"
		tell process "Mail"
			click menu item "Take “GMAIL” Offline" of menu 1 of menu item "Online Status" of menu 1 of menu bar item "Mailbox" of menu bar 1
		end tell
	end tell
else
	display notification "To take a mailbox offline, Mail must be open." with title "Mail - Not Open"
end if
end alfred_script

 

Thanks a ton guys!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...