Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppleScript Clicking On dialog box

In PCSX, (ps1 emulator), i'm trying to automate the steps to play an iso. So, i'm doing this:

set thepath to path to me
set thesecondpath to POSIX path of thepath
set thethirdpath to "Contents/PSX/ROMS/img.bin"
set thefourthpath to "/Contents/PSX/PCSX.app"
set thefifthpath to thesecondpath & thefourthpath
set theultimatepath to thesecondpath & thethirdpath

tell application thefifthpath
    activate
    tell application "System Events"
        keystroke "i" using {command down}
        keystroke theultimatepath
        delay 1.0
        tell process "PCSX"
            click button "Go"
        end tell
        key code 53
    end tell
end tell

Running from the AppleScript Editor won't work. I made it to work running from the App it creates. PCSX and the img.bin are inside the Generated Package.

after pressing command+i, it opens a "Go to the folder" dialog, and i need to click Go and then Open

But doing this way, it won't find the dialog box. What am i doing wrong?

like image 303
ghaschel Avatar asked Mar 24 '26 07:03

ghaschel


2 Answers

If Go and Open are the default buttons, try:

tell application "System Events"
    keystroke return
    delay 2
    keystroke return
end tell

Although I don't have PCX installed here is an example of how to click the Go button from Finder's Go to Folder command.

tell application "System Events"
    tell process "Finder"
        click button "Go" of window "Go to Folder"
    end tell
end tell
like image 184
adayzdone Avatar answered Mar 27 '26 05:03

adayzdone


The reason your script won’t work from AppleScript Editor is that the “me” in “path to me” is the application that ran the AppleScript. When you are running the AppleScript in AppleScript Editor, that means AppleScript Editor itself. When you saved your AppleScript as a script application and ran it, the path to me pointed to your script application, because it was running its own AppleScript.

Also, this is incorrect:

tell process "Finder"
        click button "Go" of window "Go to Folder"
end tell

The “Go” button is not on the window “Go to Folder.” It’s on a sheet which is attached to a Finder window which has the name of whatever folder is currently being viewed. So you have to describe the button as being on sheet 1 of window 1:

tell application "System Events"
    tell process "Finder"
        click button "Go" of sheet 1 of window 1
    end tell
end tell

… but keep in mind that in another app, a similar looking button on a sheet may be on sheet 1 of group 1 of group 2 of window 3. UI Scripting is complicated.

like image 20
Simon White Avatar answered Mar 27 '26 06:03

Simon White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!