Skip to main content
Complete example, explanations
Source Link

Change the program and argumentsplist to

<?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>G-key-pusher</string>
    <key>Program</key>
    <string>/usr/bin/osascript</string>
    <key>Program</key>
    <string>/bin/sh</string>
    <key>ProgramArguments</key>
    <array>
        <string>sh</string>
        <string>-c</string>
        <string>while sleep 5; do /usr/bin/osascript -e 'tell application "System Events" to keystroke "g"'; done</string>
    </array>
    <key>ServiceDescription</key>
    <string>Auto Keypress</string>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

and change the scedulingWhat it does, is to just run a shell script that does the process5 second timer and keepcalls osascript. The launchd plist just ensures the script is restarted if it alivewere to die for some reason. Please note that I thinkstill haven't tested this, but I don't see any reason why it shouldn't work. Though I have had problems in the appropriate method ispast when changing launchd items, which I fixed by changing the label. Which reminds me, you had omitted the value for the Label key in your plist.

<key>KeepAlive</key>
<true/>

(Edit: Explain a little, and provide a complete file instead of explaining what parts need to be changed.)

Change the program and arguments to

<key>Program</key>
<string>/bin/sh</string>
<key>ProgramArguments</key>
<array>
    <string>sh</string>
    <string>-c</string>
    <string>while sleep 5; do /usr/bin/osascript -e 'tell application "System Events" to keystroke "g"'; done</string>
</array>

and change the sceduling to just run the process and keep it alive. I think the appropriate method is

<key>KeepAlive</key>
<true/>

Change the plist to

<?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>G-key-pusher</string>
    <key>Program</key>
    <string>/usr/bin/osascript</string>
    <key>Program</key>
    <string>/bin/sh</string>
    <key>ProgramArguments</key>
    <array>
        <string>sh</string>
        <string>-c</string>
        <string>while sleep 5; do /usr/bin/osascript -e 'tell application "System Events" to keystroke "g"'; done</string>
    </array>
    <key>ServiceDescription</key>
    <string>Auto Keypress</string>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

What it does, is to run a shell script that does the 5 second timer and calls osascript. The launchd plist just ensures the script is restarted if it were to die for some reason. Please note that I still haven't tested this, but I don't see any reason why it shouldn't work. Though I have had problems in the past when changing launchd items, which I fixed by changing the label. Which reminds me, you had omitted the value for the Label key in your plist.

(Edit: Explain a little, and provide a complete file instead of explaining what parts need to be changed.)

Source Link

Change the program and arguments to

<key>Program</key>
<string>/bin/sh</string>
<key>ProgramArguments</key>
<array>
    <string>sh</string>
    <string>-c</string>
    <string>while sleep 5; do /usr/bin/osascript -e 'tell application "System Events" to keystroke "g"'; done</string>
</array>

and change the sceduling to just run the process and keep it alive. I think the appropriate method is

<key>KeepAlive</key>
<true/>