Applescripting - down arrow to highlight and select file within a Photoshop CS5 choose file window

微笑、不失礼 提交于 2019-12-11 02:55:02

问题


Hello and Thank you for any help whatsoever,

I am writing a script to write a long list of file formats by accessing Adobe action scripts.

My problem is that I cannot seem to access a file with a down arrow within the script once it is in a photoshop "choose file" window.

I would have it open a specific file by path but this file name will change constantly.

Here is what I have

tell application "Adobe Illustrator"
do script "eps format save" from "Default Actions" without dialogs
end tell
delay 2
tell application "Adobe Photoshop CS5"
set myFile to (choose file) as string
open file myFile
delay 4
tell application "System Events"
    key code 125 -- **DOES NOT KEY DOWN**
            key code 36  -- **FOR SELECTING THE CHOOSE BUTTON ONCE HIGHLIGHTED**
end tell
    delay 4
tell current document
    do action "saving formats" from "Default Actions" -- action and set name,     case sensitive
end tell
end tell

And to tell you the truth I would love for it to open any file within a specified path to the folder it is in so that there are no glitches later.

Thank you for any help


回答1:


You can't do as you ask. First, regarding the choose file dialog, it is not a "photoshop" choose file dialog. It is an applescript dialog box. It doesn't matter that you have it inside the photoshop tell block of code, applescript is executing the command not photoshop.

Second, when the choose file dialog is open the entire script pauses waiting for you to actually choose a file in the dialog. So the system events code to press the down arrow does not execute until after the dialog box is dismissed. As such the system events code isn't run when the dialog is showing.

In general your whole approach will not work. To illustrate notice this won't work. You have to manually choose the file before the system events code will run.

set myFile to (choose file) as string

tell application "System Events"
    key code 125
    delay 0.2
    key code 36
end tell

return myFile

But there is a trick you can use. We can issue the system events code before the choose file dialog is shown, make that code delay 3 seconds before it is run, then when it does run it will effect the choose file dialog. We can do this by running the system events code through the shell. Try this...

do shell script "/usr/bin/osascript -e 'delay 3' -e 'tell application \"System Events\"' -e 'key code 125' -e 'delay 0.2' -e 'key code 36' -e 'end tell' > /dev/null 2>&1 &"
set myFile to (choose file) as string
return myFile

So now we can put this in your script to open the chosen file in photoshop.

-- do illustrator stuff here

do shell script "/usr/bin/osascript -e 'delay 3' -e 'tell application \"System Events\"' -e 'key code 125' -e 'delay 0.2' -e 'key code 36' -e 'end tell' > /dev/null 2>&1 &"
set myFile to (choose file) as string

tell application "Adobe Photoshop CS5"
    open file myFile
    -- do photoshop action stuff here
end tell


来源:https://stackoverflow.com/questions/20227234/applescripting-down-arrow-to-highlight-and-select-file-within-a-photoshop-cs5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!