Brief, Silly Q Re Simulating Keystrokes

I’m no apple script master but I used to use a simple script to input a file’s password:

set keyValue to “12345”
tell application “System Events” to keystroke keyValue
set keyValue to return
tell application “System Events” to keystroke keyValue

or

set keyValue to “12345” & return
tell application “System Events” to keystroke keyValue

but it seems that it no longer works. I have 10.10.1 on a minimac. I sure would be appreciative if someone can help me out. Thanks in advance.

Model: mac mini
AppleScript: 2.4
Browser: Firefox 35.0.1
Operating System: Other

Hi.

It does still work and should do whether you’ve got GUI Scripting enabled or not, but I can’t find the GUI Scripting setting at the moment to see if the latter statement’s still true.

I did find your script didn’t work when I tried it in Script Editor. This turned out to be because I was running it using the Command-“r” keyboard shortcut and the held Command key was changing the effect of the scripted keystrokes!

Under Yosemite, we must give the script (if it is saved as an application) or to the Script Editor, the permission to apply GUIScripting commands thru the pane “Confidentiality” of the preference pane “Security and confidentiality”.

I wish to add that it’s often useful to speak to an application process with this kind of instructions :


set targetApplication to activate
tell application "System Events" to tell process targetApplication
set frontmost to true
#.
end tell

Yvan KOENIG (VALLAURIS, France) lundi 9 février 2015 17:59:36

Yvan, My Preference panel says Security and “Private” (not “Confidentiality”) (could it be that I have 10.1.1?). I went through the every Systems Preference panel and could not find GUI scripting. Also, I tried your script and it wouldn’t work: It kept asking me define “target application” and there again, I tried everything and couldn’t define it. Is there something I’m missing?

Hello

When you send a mail asking a question to somebody, it would be polite to give a valid address for the answer.

I tried twice to answer using the given address xxxx@hotmail.com and my mails were rejected.
Of course xxxx is a fake string because on my side I’m polite enough to refuse to make public an address without the person’s permission.

I am a French citizen so I run the system in french.
Here, the preference pane is named “Sécurité and confidentialité” which I translated as “Security and confidentiality” which is not more bad than a google translation. Next time I will give only the french name !
In the sample script which I posted, I’m sure that every reader minus you understood that targetApplication was use to name the application to which you are trying to send some keystroke.

Yvan KOENIG (VALLAURIS, France) mardi 10 février 2015 18:11:45

No squabbling, please.

The English for “Sécurité et confidentialité” is “Security & Privacy”.

machover99: Yvan’s script in post #3 was just a sketch to show how to bring an application process to the front in order to receive keystrokes ” something I didn’t mention myself in post #2. You have to substitute the name of your application ” in quotes ” for ‘targetApplication’.

If you’re running your script from Script Editor, you’ll have to allow Script Editor under “Accessibility” in the “Privacy” pane of the “Security & Privacy” preferences. If you’re running it from the Script Menu, you’ll need to allow “SystemUIServer.app”. If you’re running it as an application, you’ll presumably have to allow the applet itself. It’s to do with the tightened security in Mac OS.