I am trying to implement a GUI with my script to access menu items in iTunes that could not be scripted…for instance, the visualizer and equalizer. The GUI works and causes iTunes to do the requested task.
Unfortunately, after iTunes exits the task the script hangs and causes the Finder to behave erratically. By erratically, I mean I could not double-click to open any application in the Dock. When I double-click any program in the Dock, the folder that contains the application opens up, from where it could be opened.
Is there a way to keep the script “alive” after iTunes exit out of the scripted task? I have tried timeout and application responses but no luck.
Any suggestion is much appreciated.
If you could share your code with us it would make it easier to spot your problem. I’ll take a wild guess and say that your script may be running something like “key down command” without getting to the necessary “key up command” line, which if not reached will cause the kind of erratic behavior you describe. Might I suggest you avoid those clauses in favor of adding “using command down” to each keystroke command that needs it, for example: keystroke “q” using command down
It’s a humungous program in AppleScript Studio already. I will see what snippet of the total code I can pull out to share to the group so as to give more light on my problem.
Meanwhile, I will try your suggestion and let you know if it worked.
Appreciate your help and will keep you posted.
Just want you and others in this forum to know…I tried your suggestion and it worked, but only after I took out the prime culprit…a timeout which I installed in the script, thinking that my script needs to wait until iTunes has finished the task (visualizer, for example).
Now, that aberrant Finder behavior that I mentioned in my earlier post is gone.
Thank for the tip.
Hi Silvermeteors and All,
I am back with another question. Why wouldn’t the codes below initiate any action in iTunes? Don’t know what the problem is. This is just a test code to see if I can get some menu items in iTunes that can’t be scripted to work via UI script.
Please check the code below and see if there is anything I must add. Thanks.
Nothing comes out…like a new window showing duplicate tracks or none if there is none…as what happens when doing it directly in the iTunes window.
Oh, and the only action taken is a description of the path to the menu item in Script Editor’s Description window below.
tell application "System Events"
tell process "iTunes" to activate
if UI elements enabled then
tell process "iTunes"
tell menu bar 1
tell menu bar item "Edit"
click menu item "Show Duplicate Songs" of menu "Edit"
tell application "System Preferences"
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
You don’t need this tell statement:
tell menu bar item “Edit”
There’s no class ‘menu bar item’.
Edit: BTW, you can script most if not all of the visulizer and equalizer menu actions. Look in the dictionary under the Application properties.
Thanks for the tip Kel.
I will try taking out the menu bar item “Edit” as you suggested and will also look further in the dictionary if I can do away with UI scripting for items like visualizer and equalizer.
Appreciate your help.
Just to update you, you’re right. Both viualizer and equalizer properties are scriptable. I’ve already done away with the UI script codes. Thanks for the lead.
BTW, when I removed the --tell menu bar item “Edit”-- in the UI codes that I posted earlier in this thread, the script returned an error. Something’s still afoot. I am still experimenting but if others have suggestions I am willing to try them and return the result back to this forum.
I think this line is not right also:
tell process “iTunes” to activate
What you’re trying to do is pring iTunes to the front, so you can use its menu. Apple gives this form:
tell app “iTunes” to activate – makes iTunes frontmost process
tell app “System Events”
tell process “iTunes”
– do whatever
That does it! Your latest suggestion to change the word “process” into “application” in activating iTunes did the trick. Now, the UI script is working. However, it is absolutely essential that the iTunes window open up…i.e., it doesn’t work when iTunes is already open but the window is hidden from view or minimized.
Thanks a lot for your patience and kind help.
‘activate’ should unhide the window I think and the following will unminimize (bring out of dock) or open a new window:
tell application “iTunes”
set visible of front window to true
Edit: or this might be better if you’re talking about the browser window:
tell application “iTunes”
set visible of browser window 1 to true
Edit: or better yet:
tell application “iTunes”
set visible of every window to true
I just tried all your suggestions to activate/unminimize iTunes window when running the UI script.
FYI, the first two worked alright. The third (open every window) also opened the Equalizer window even though it is closed before the UI script runs.
I am sticking with the “set visible of front browser window to true”.
Thanks for the tips. I do appreciate your help.