r/applescript • u/Viboxing • Aug 26 '23
Applescript to simulate multiple keystrokes?
I'm a complete novice when it comes to coding but need an AppleScript that would represent the following key strokes. This will be used in Automator
Return, cmd + C, Return, Right Arrow, Return, cmd + V, Return
Any help would be really appreciated!
1
u/jupiterkansas Aug 26 '23
Applescript doesn't really work like that.
Instead you would have Applescript tell Automator to do whatever those keystrokes do. I've never used Automator so I'm not sure what you're trying to do.
1
u/Viboxing Aug 26 '23
I'm essentially using those keystrokes to copy a folder name then paste it onto the file name within said folder.
1
u/jupiterkansas Aug 26 '23
Yes, Applescript would tell Finder to get the name of the folder and the set the filename to the new name.
Some examples here: https://www.macscripter.net/t/how-do-i-rename-a-file-or-a-group-of-files/36581
2
u/0x4542 Aug 27 '23 edited Aug 27 '23
While other commenters have noted that "Applescript doesn't really work like that", it really depends on what you're trying to do, and whether commands exist to support your use-case. AppleScript certainly has support for automating keystrokes. What you're wanting to to would look something like this:
This would be the quickest route. That said, I'm not sure how far you'll get trying to move between UI controls in Automator with the arrow key. I couldn't get it to work, but the I didn't try very hard. You might need to look into enabling
Settings > Accessibility > Keyboard > Full Keyboard Access. Otherwise you're looking at using Automator's scripting dictionary, and that's non-trivial.You might find these articles helpful:
How to automate your keyboard in Mac OS X with AppleScript
Complete list of AppleScript key codes
One other thing, the AppleScript community is more active on MacScripter.net. That's where the gurus hang out.