You can do this in AppleScript, iff you've enabled access for assistive devices:
tell application "System Events" to keystroke "," using command down
This will (obviously) invoke cmd-,.
If, for some reason, you can't enable access for assistive devices, then it's pretty easy to do this in code (by creating a CGEventRef
and then posting it to the system, essentially). If you'd like help with that, then head over to stackoverflow.com, where that question has been asked a few times.
As for getting this to happen every 60 seconds, you could turn it into a launch agent and let launchd do it for you:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.stackexchange.apple.12692</string>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>-e</string>
<string>tell application "System Events" to keystroke "," using command down</string>
</array>
<key>ServiceDescription</key>
<string>Auto Keypress</string>
<key>StartCalendarInterval</key>
<dict>
<key>Second</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Toss that in ~/Library/LaunchAgents and you should be good to go (once you load the plist and/or log out and log back in).
The open()
handler gets passed an alias
(which is a kind of a pointer to a file or folder). You can then simply convert the alias to text, but it will show you the path with colons as separators (e.g. "Macintosh HD:Users:Username:Documents:Folder:").
Use POSIX path of
to convert it to a UNIX-style path with "/" separators, and if you want to paste it into Terminal, especially if the path has spaces in it, you should use quoted form of
to properly enclose it in quotes.
The following script works with both folders and files for me, when an item is passed to it via LaunchBar:
on open (thisItem)
display dialog (thisItem as text) -- alias
display dialog quoted form of POSIX path of thisItem -- POSIX path
end open
Best Answer
How to send enter key using Applescript
In order to send the enter key in applescript you can use:
Alternatively:
The Difference between the two:
As shown here
key code 36
is used to send the key Return.key code 76
on the other hand is used to send Enter.(@user3439894 Pointed out that
key code 36
is typically used.)Fixing Applescript not being able to send keystrokes
Article
More Info
Sending Keystrokes: How to send special keys Applescript, How do I automate a key press in AppleScript? and List of Apple Key Codes
Fixing applescript not being able to send keystrokes: Application is not allowed to send keystrokes