How to access drop down in application using applescript? - applescript

I'm trying to tell applescript to open the app, Application Loader, and choose from the drop down list that's in the window. The item that should be chosen will always be the very first item. How do i do this?
Thanks in advance.

Wow I finally got it working! I pretty much got mad at my script so I just put a random ASCII number and it magically worked. I got pretty happy aha :)
activate application "Application Loader"
tell application "System Events"
tell process "Application Loader"
tell the first combo box of window 1
delay 3
keystroke (ASCII character 30)
keystroke (ASCII character 12)
keystroke return
end tell
end tell
end tell

Related

AppleScript works in Script Editor but not as application

I am pretty new to programming, especially with AppleScript. I wrote a simple script for Valentine's Day to play a song from iTunes and then open a flash animation file in Safari. When I run the script in ScriptEditor, everything works as desired, but when I export as a standalone application, it fails at the command to enable full-screen mode. I am assuming it is an issue with System Events. To be clear, the application functions to the end, but at the keystroke command I hear an alert sound and the window remains as-is.
I am running Yosemite, and am fully updated.
Ideally, I would like to open the file in Google Chrome to utilize Presentation Mode, but I can't even get Chrome to open the file.
Thanks for any advice! Here is the code:
tell application "Finder"
set visible of every process whose visible is true and name is not "Finder" to false
close every window
end tell
set volume output volume 75
tell application "iTunes"
set currentVolume to sound volume
if player state is playing then
stop
back track
end if
play track "The Promise"
set player position to 6
end tell
delay 4
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new window at front
end if
open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
tell application "System Events"
tell process "Safari" to keystroke "f" using {command down, control down}
end tell
end tell
I agree with Jerry Stratton's comment that it could be an accessibility issue. However it also could be that you are issuing the keystroke command before Safari is ready to accept it. If it's opening a file then it could be busy and miss the keystroke command.
Also, I would move the system events code outside the Safari code and also just tell system events, rather than the Safari process, to perform the keystroke command. Try this as the Safari and System Events parts.
NOTE: I can't get Chrome to open a file either.
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new window at front
end if
open (POSIX path of (path to home folder)) & "/Desktop/beMine/beMine.swf"
end tell
tell application "Safari" to activate
delay 1
tell application "System Events"
keystroke "f" using {command down, control down}
end tell
Most likely you’ll need to allow your standalone application to use System Events. At some point you needed to do that for Script Editor; you’ll need to do the same for your standalone app.
You’ll find the option in System Preferences under Security & Privacy, then Privacy, and then Accessibility. There’ll be a list of apps, and your app is probably listed there without a check for “Allow the apps below to control your computer.”
You may need to use the “+” button to add your app to the list.
I have verified that I can use this simple script to make Safari full-screen; it will work if the app is given permission under Accessibility, and it will silently fail if not.
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari" to keystroke "f" using {command down, control down}
end tell
This is Yosemite, Mac OS X 10.10; it may be different in other versions of Mac OS X.

Applescript: open Dropbox preferences

Is there a way to open Dropbox preferences using Applescript?
I tried:
tell application "Dropbox" to open "Preferences"
I saw an earlier Stack Overflow posting but it's from 2011.
I had to get a little create, but got it to work eventually. This script opens the Dropbox preferences:
tell application "System Events" to tell process "Dropbox"
tell menu bar item 1 of menu bar 2
click
end tell
tell window 1
tell scroll area 1
tell UI element 1
tell group 33
click
keystroke "Preferences..."
keystroke return
end tell
end tell
end tell
end tell
end tell
However, after the click is performed, there is a 5 second delay before it performs the keystroke.
This is an issue which has been reported by a lot of people, but I haven't found a solution for this yet.

script auto correcting incorrectly when i compile and key down key up not working as well

alright I'm currently having a lot of issues with my applescript editor. currently when ever i do a Key up key down sequence it will always key the letter A. for example.
tell application "System Events"
key down "u"
key up "u"
delay 1
end tell
this will keystroke A and i don't know why.
^ thats only a minor issue though my big problem is that i want to swap between three different video game applications. They are all a duplicate of the same game. Heres how my basic script goes.
tell application "Video Game" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
tell application "Video Game copy" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
tell application "Video Game copy 2" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
The problem is when i try to compile the script the application name always corrects to "Video Game".
Any ideas on how to keep it from compiling in correctly?
I have tried putting in a bogus name then when applescript asks me to find the app i click the correct one under the browse search box. and it will still compile incorrectly.
thanks a bunch :)
what you describe seems a bug in applescript. Here is a little workaround for that. I wrote it for jxa (javascript for ui automation), so you have to port it to applescript i think:
ObjC.import("Cocoa");
function key(aiKeyCode, aiDelay)
{
var source = $.CGEventSourceCreate($.kCGEventSourceStateCombinedSessionState),
keyDown = $.CGEventCreateKeyboardEvent(source, aiKeyCode, true),
keyUp = $.CGEventCreateKeyboardEvent(source, aiKeyCode, false);
$.CGEventPost($.kCGAnnotatedSessionEventTap, keyDown);
delay(aiDelay);
$.CGEventPost($.kCGAnnotatedSessionEventTap, keyUp);
}
keystroke will get the key to be pressed once. It helps to tell the process App you are telling System Events to do something, i.e.
tell application "System Events" to tell process "App Name" to keystroke "u"
If you want to do it with command, option, shift, etc. use this:
tell application "System Events" to tell process "App Name" to keystroke "u" using {command down, shift down, option down}
What AppleScript Editor is doing is not “autocorrect” — it’s “compiling.” It’s not doing it incorrectly. You can change the name of an app on the Mac and it doesn’t break the app. AppleScript Editor is still able to find the app “Video Game” even if you change its name to “Video Game copy 1.” This is a feature, not a bug.

make applescript auto-click

I play a game in Safari.
I want to make an applescript that auto clicks for me in a special spot on the screen, I have tried many things but none of it has worked for me.
Any ideas how to do it?
You can record the mouse movement with Automator and play this record: you can save it as application, too...
It's the easiest way, in my opinion...
delay 3
tell application "System Events"
tell application process "TheApp"
key code 53
delay 1
click (click at {1800, 1200})
end tell
end tell
However, it doesn't seem to work in Mavericks.
I was trying to achieve the same thing as you a few months/years ago :)
I was botting(the thing you want to achieve) a game named Runescape =P
Of course it is against the rule so you may get banned :S
As sylter says you can use Automator to automate your task (which is the only solution) i tried to click the mouse button but i was not able to find out how :/
you should use automator! it is REALLY easy :)
repeat 10 times
delay 1
tell application "System Events"
tell application process "Safari"
click (click at {650, 730})
end tell
end tell
end repeat
should work for you

Make ESCAPE (ESC) key close window

How do I make an application that I can make the ESC key close a window? Or really any key (I can change if I want to).
Please help. Thanks
Here is what I have and I can't get it to work.
-- close window with "ESC"
tell application "System Events"
tell application "Finder" to activate
key code 53
end tell
beep 3
Thanks! B-
There's a system wide shortcut (Command + W) that will close the currently activated window
tell application "System Events"
tell application "Finder" to activate
keystroke "w" using command down
end tell
However, I'm not sure that this answers your question. Its impossible to use plain AppleScript to listen to system wide keyboard events. Take a look at the answer to this question.
PCWiz's link should show you the way - have a look at the second answer (by ghoppe - setting keyboard shortcut to application in preferences). Just remember to save the script as application, otherwise it'll not be eligible.

Resources