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.
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.
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.
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.
TIA
archseed
on run
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"
end tell
end tell
end tell
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
end tell
end if
end tell
end run
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.
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.
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.