Jasondm007 Posted October 10, 2017 Share Posted October 10, 2017 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 Posted October 10, 2017 Share Posted October 10, 2017 Can't test it, so this may not work, but usually with AppleScript you use & quote & to if you need to add " to a string, i.e.: click menu item "Take " & quote & "GMAIL" & quote & " Offline"... Link to comment
Jasondm007 Posted October 11, 2017 Author Share Posted October 11, 2017 (edited) @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): This is driving me crazy! Thanks for any help you can lend. Edited October 11, 2017 by Jasondm007 Link to comment
vitor Posted October 11, 2017 Share Posted October 11, 2017 (edited) Also untested. Maybe click menu item "Take " & quoted form of "GMAIL" & " Offline"…? Edited October 11, 2017 by vitor Link to comment
Jasondm007 Posted October 11, 2017 Author Share Posted October 11, 2017 Thanks for trying @vitor ! Unfortunately, no luck with it either (another syntax error). Link to comment
deanishe Posted October 11, 2017 Share Posted October 11, 2017 Now that I think about it, they’re probably “smart” quotes. IIRC, you press ALT+[ and ALT+SHIFT+[ to get them. Maybe ]. I can’t remember which is double and which is single quotes. kristof 1 Link to comment
vitor Posted October 11, 2017 Share Posted October 11, 2017 @deanishe The shortcut depends on the keyboard/language. I don’t remember the English shortcuts, but they’re different from the Portuguese ones: ⌥, → “ ⌥⇧, → ” ⌥l → ‘ ⌥⇧l → ’ Link to comment
Jasondm007 Posted October 12, 2017 Author Share Posted October 12, 2017 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
deanishe Posted October 12, 2017 Share Posted October 12, 2017 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
Jasondm007 Posted October 12, 2017 Author Share Posted October 12, 2017 @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 Posted October 12, 2017 Share Posted October 12, 2017 8 minutes ago, Jasondm007 said: how do you create those in an applescript? You type them. As I said above, ⌥[ and ⌥⇧[ on an English keyboard get you opening and closing smart double quotes. kristof 1 Link to comment
Jasondm007 Posted October 12, 2017 Author Share Posted October 12, 2017 @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! kristof 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now