1

My query is very similar to: Can a Mac be programmed to simulate pressing a key at a certain rate via software? whereby need to have script, so the Macbook won't lock automatically (caffienate -t is not working due to policy). The keystroke also needs to be a safe key (like SCROLL LOCK2 or very passive key) which doesn't do any harm.

Do you know how to replace the keystroke of SCROLL LOCK2 or "fn" key via command

# below one just inserts "fn" characters, which  is dangerous 
echo "set i to 0
repeat while i < 15
set i to i + 1
delay 5
# Trying out fn key, but not sure what is the keystroke value of it?
tell application \"System Events\" to keystroke \"fn\"
end repeat" | osascript
  • If this is whilst unattended, why not just use a hot corner? – Tetsujin Jun 07 '21 at 11:56
  • @Tetsujin, quite didn't get you. How can it send a "keystorke" or move the mouse automatically every 60 seconds? – diaryfolio Jun 07 '21 at 12:30
  • You don't need to, if all you're trying to do is keep the Mac awake whilst unattended. Your question seems to be an XY Problem - You want to do X, & you think in order to achieve X you must do Y. However you don't know how to do Y, so you ask how to do that… when in fact what you needed to do was X. – Tetsujin Jun 07 '21 at 12:33
  • Not actually true. The organisation policy does NOT allow me to change the sleep, power settings or how long it can be awake. So I've to simulate the key – diaryfolio Jun 07 '21 at 12:37
  • I didn't suggest changing any of those. You're still on the Y of the XY problem. – Tetsujin Jun 07 '21 at 12:43
  • Also why does the organisation ban these things. They should have a reason and a solution has to meet that reason as well. – mmmmmm Jun 07 '21 at 13:11
  • @mmmmmm - Corporations quite rightly don't want their data to be accessible whilst the employee is away from their computer. Bypassing this could easily be good cause for dismissal. I have taken the liberty during this discussion of assuming this would be for the OP to be working from home & in a less 'dangerous' situation. – Tetsujin Jun 07 '21 at 13:25
  • I think the below link gives the details of various keystrokes https://apple.stackexchange.com/questions/36943/how-do-i-automate-a-key-press-in-applescript Also a nice list of key-codes https://css-tricks.com/snippets/javascript/javascript-keycodes/ – diaryfolio Jun 07 '21 at 13:22
  • @Tetsujin Yes I agree - my comment was to the OP to point out that any solution must keep to the rules – mmmmmm Jun 07 '21 at 13:53
  • @mmmmmm - Indeed, hence my original suggestion. It requires no access to protected areas, nor any script at all. Simply move the cursor to the set hot corner & Bob is a sibling of your parent ;) – Tetsujin Jun 07 '21 at 13:55

3 Answers3

1

I'm going to add this as an answer anyway, though it wasn't given much credence in comments;)

Set a hot corner to 'Disable Screen Saver' then as you leave your desk, just push the cursor into that corner. If the screen doesn't sleep, neither does the Mac.
This requires no admin permissions as far as I'm aware. The screensaver control panel is not locked by default.

enter image description here

Tetsujin
  • 115,663
0

I realize that this question was asking for a software solution, but given the comments on the question it sounds like this would be much easier with a hardware solution. With typical IT governance tools it may be effectively impossible to do this in software on the work laptop.

Without the software requirement, the clear solution to this issue is an auto clicker/tapper. You can get an "auto clicker" on Amazon for <$30. It plugs into USB and can tap at various rates.

Searching for auto clicker also brings up various software solutions, so you might try that out before trying to code this yourself or buy a hardware solution.

chicks
  • 113
  • Ignoring for the moment that circumventing security measures often isn't a good idea: Isn't it rather cumbersome to work on a computer if the mouse auto-clicks every 30 seconds? – nohillside Jun 07 '21 at 14:20
  • 1
    @nohillside, agreed. But one of the clients computer policy is not practical and locks out in 60 seconds ! by the time you stand and stretch it get's locked out. Security is a compromise with user friendliness – diaryfolio Jun 07 '21 at 14:38
0

Below link gives the details of various keystrokes Also a nice list of key-codes https://css-tricks.com/snippets/javascript/javascript-keycodes/

Based on above, the idea to do programatically (via applescript) is

  • To create a script file with detail
  • Load it and run every 59 seconds (eg if the lockout period is 60 seconds)

Create applescript with scroll-lock press: 145_scrolllock.scpt

    tell application "System Events"
        key code 145 using {shift down, command down} -- shift-command-left
    end tell

Now create a plist: 145_scrolllock.plist

<?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>Disabled</key>
        <false/>
        <key>Label</key>
        <string>145_scrolllock</string>
        <key>Program</key>
        <string>/usr/bin/osascript</string>
        <key>ProgramArguments</key>
        <array>
                <string>osascript</string>
                <string>./145_scrolllock.scpt</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>60</integer>
</dict>
</plist>

Load it whenever you want and will execute automatically

launchctl load ~/somelocation/145_scrolllock.plist 
launchctl start 145_scrolllock