![]() |
Applescript: How do I select menu item with Quotes
Hi all, I'm new to this forum, but not new to Macs or Programming. Just got my iPhone and was looking to do some automating.
I'm trying to automate the clicking of the File->Sync "Jordan's iPhone" menu item in iTunes. Notice the Quotes around "Jordan's iPhone". Here's what I have: PHP Code:
Quote:
Quote:
PHP Code:
The Method menu_click was provide by jacobolus (maxosxhints), and all works fine. PHP Code:
|
I have to say, I love it when Apple decides not to play by their own rules. <sigh...>
when I investigated this (and please note that I checked it out with my iPod on the assumption that that would work equivalently to the iPhone), I found that even though the visible menu says Sync "so-and-so's iPod", in fact, the system only sees Sync iPod. you can test this for yourself by inserting the following code in an appropriate place in your script: Code:
tell application "System Events"needless to say, I prefer option 2 :D |
tw,
Thanks so much for the response. I tried just "Sync iPhone" and it didn't work. And I couldn't get the list via the code you sent. I added your code and got the error: Quote:
PHP Code:
|
sending your script back at you, with revisions (in red)
Code:
set inputStr to "iTunes, File, Sync iPhone" |
tw,
That helped a lot. Here's the strange thing ;) All menu items that have quotes or "..." after them fail. All other menu items work great! ;) Is that nuts or what? With the same code were you able to click on an item with ... let's say set inputStr to "iTunes, File, New Smart Playlist..." Isn't that strange behavior or is there some trick to it? |
It might be that the OS menu handler is putting the name into a placeholder, and that the actual menu item text you see is not what the menu description is (I think I got that right), so a matching comparison is failing somewhere.
By the way, you can skip all that assigning to a string and text item delimiter stuff by just directly passing the list items (the handler code is confusing enough): menu_click({"iTunes", "View", "Full Screen"}) |
well, I understand the '...' problem. apparently, iTunes is not using three periods, but rather a single charachter called the horizontal ellipsis (it looks like three dots, but it's really a single entity, go figure...). if you can find that character and paste it into your script instead of three dots, that would work.
in case you're curious, this is the character - … - and this is three dots in a row - ... -. hope that comes through in the forum. also, when I look at the list of menu items that comes out of applescript, there aren't any with quotes in them. you shouldn't have to use quotes anywhere here, apparently. |
I also use a constant for the elipse, but I was referring to the original problem. I have seen some string definitions with placeholders like "Do Something %1", and was wondering if something like that was causing the problem, since there are quotes in the menu item, but apparently not in the menu definition.
|
Quote:
|
I couldn't figure out how to select a menu item with quotes in it so I scrapped the whole thing and looped through the menu items using the code that "tw" provided. I used an offset to find what I was looking for. By keeping track of the count I was then able to do click menu item (count).
It bugs me that I couldn't figure it out, but I don't know Applescript all that well so alas, resigned to defeat. Thanks for all of your kind help. This is a terrific board. Much appreciated all of the responses. Cheers, Jordan |
Quote:
so, plug in your iPhone, launch iTunes, take a deep iBreath, and run this simplified script - it will do nothing except make a list of iTunes' File menu items in TextEdit. copy that list into your next post here and let us see what we can see. Code:
tell application "iTunes" to launch |
Here's the output even with the iPhone in the cradle and Sync "Jordan's iPhone" under the File Menu.
Quote:
Quote:
|
well faaaaaaascinating. according to this, iTunes treats your iPhone as though it were an iPod. try using "Sync iPod" in your script when your iPhone is plugged in, see if you get the results you expect.
|
Ah HA! Success is mine!
The reason for the goofiness is that the characters are NOT the standard quotes, but the left and right double quotation marks! (Troubleshooting tip: copy and paste text from the results window to a text editor like BBEdit) I was unable to get an ascii number for the characters, but you can use Unicode or paste the character from the input menu (Script Editor > Edit > Special Characters…) into a string variable. For Example: set LeftQuote to "“" set RightQuote to "”" menu_click({"iTunes", "File", "Sync " & LeftQuote & "Jordan's iPhone" & RightQuote}) |
Quote:
Code:
set RQNum to ASCII number of "“" -- returns 210 |
Hmmm - I was using ASCII 201 for the elipse, but the other characters failed for some reason at the time. Seems to be working now though, must be getting late or something...
|
Sorry to come in so late.
But have you tried Code:
tell application "iTunes" |
OMG! ;)
mark_hunte in five minutes you did what I was trying to do in a day and a half. ;) Modified a little bit, but works just fine: PHP Code:
Do you know what I mean? In that scenario, I'd need to check the menu items. Do you agree? So now, looks like I have to go back to Red_Menace's or tw's suggestion of using Left/Right quotes or ascii codes respectively. btw: tw, I did try "Sync iPod". It didn't match, so iTunes definitely knows there's a difference. |
Latest update: Check out this line. (Something happened in the cut and paste, probably encoding from UTF-16 to UTF-8).
In Applescript, the menu items has curly quotes around Jordan's iPhone. Seems to make a difference because the offset says there is NO MATCH. Quote:
The objective is to select the Menu item by Name. As in: Quote:
|
Quote:
I will say that I remember reading a nice discussion of this on the Satimage website, somewhere, but for the time being you might have to use the cut and paste approach. as to specifying updates - well, a quick glance at the iTunes AS dictionary shows that the update command has an optional source parameter. don't know the syntax they are looking for, but that should allow you to specify which device you're updating. |
Quote:
|
Apple sure could have made this easier... lol
|
The thing is you should not need to enter the name of the menu item in the script, but use what you have to get the script to do it for you.
Code:
activate application "iTunes"if SyncItem contains "iPhone" then |
Good idea (see, this is why I don't program for a living) - my menu click handler now just looks if the item is contained in one of the menu items. In case anyone is interested, here is the handler:
Code:
on run -- example |
Red_Menace and Mark Hunte,
Just wanted to follow up with an update. I dropped the project and worked on some other things before Red posted the solution above. Went back to the project today and BINGO! the code works flawlessly now. I'm so excited I don't know what to do. Thank everyone for contributing to this post, I'm sure it helps tons of people. Thanks, Jordan |
| All times are GMT -5. The time now is 05:51 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.