r/applescript • • 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 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/Viboxing Aug 27 '23

tell application "Automator"tell application "System Events"

keystroke returnkeystroke "c" using command downkeystroke returnkey code 124keystroke returnkeystroke "v" using command downkeystroke returnend tellend tell

I really appreciate your help however my idea of trying to use a hotkey sequence to rename a file to the same as the folder name was not well thought out.

I'm using the script in collaboration with Hazel so when the file is automatically organised into said folder, it will then take on the folder name and change automatically. Screenshot for reference.

https://i.imgur.com/h3z7hse.png

Step 1: Drag folders into parent folder

Step 2: Hazel will organise them into individual folders

Step 3: Rename file using same name as its sub folder

I found some code online which works but I have to specify which folder I want to monitor each time I want to run the script. I'll jump to Macscripter if needs be and see if someone there can help :)

1

u/0x4542 Aug 27 '23 edited Aug 27 '23

Fair enough. It does sound more involved that I imagined.

I've never used Hazel, but it does seem to support running AppleScript in a rule action. Perhaps that can be where you insert your code as part of Step 3 above? I'm sure you'll get a lot of help on MacScripter. Those people are very supportive.

They might even suggest using AppleScript's own folder actions. It might even be simpler than trying to hook into Hazel's own way of doing things.