In UI, trying to press Command, but pressing shift+command

Hi All,
I am using ui scripting and want to copy the contents of pdf file to a text file. Following is sample of script…
Now my problem is that : In one of script step, in place of pressing “A” with command, to select all text of pdf file, script presses “A” with shift and command. And for “C” with command also, it is pressing shift+command. Where as in script I have only asked to press Command key. What could be cause to press shift with command.

Script Sample :

tell application "Preview.app"
    activate
    open alias thisItem --open the file we are on, this works fine
    delay the 10 -- giving time to get open
end tell
tell application "Preview" to activate
tell application "System Events"
    tell process "Preview"
        keystroke "A" using command down --select all, here is the issue.
        delay the 10 -- giving time to get selected all
        keystroke "C" using command down --copy all, here is the issue again.
        delay the 10 -- giving time to get everything on clipboard
    end tell
end tell

=============================
Any clue will be helpful.

Try lowercase, perhaps. (Totally a guess.)

You can’t do with UI scripting something you can’t do with the app itself. If you look at the edit menu of “Preview” you’ll see that “Select All” is dimmed - it doesn’t work. Preview, in other words, is totally unscriptable. “thisItem” would have opened in Preview anyway, without the "tell app “Preview” block, if Preview is your default viewer for the type of file “thisItem” represents.

Thanks for your replies. I tried lower case and no luck.
Also, If you select, “Text Tool” under Tools menu option then “Select All” is not dimmed. I can select all using command+a in app manually.
Any other hints please.

after removing

tell application "Preview.app"
activate
open alias thisItem --open the file we are on, this works fine
delay the 10 -- giving time to get open
end tell

and changing to lowercase, it worked for me on a PDF of text.

j

Am I drunk, Can not be !!!
This time it worked replacing upper case to lower case. I swear to my apple that I did try this before.

Anyway, Thanks a bunch for all helps. (After struggling for few hours, when I could not find answer, I knew that this forum will help me, as always).

What if for some reason it takes longer than 10 seconds to open the file? You should go into a wait loop that checks every few seconds until a certain timeout period has elapsed.

I was just testing the script. The first part didn’t work for me at all as written, so I tested the rest on an open file. I don’t have any PDFs that take that long to open, but point taken.

You don’t have any that you tested. You also cannot predict when something in the environment will force your script to wait more than 10 seconds. What if Preview decides it’s time to start paging in when you tell it to open the file? You end up waiting 15 seconds and then your script fails. Oops. :wink:

Understood. Which is why I said, and will repeat, point taken. :slight_smile: