aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Segundo2025-03-19 14:18:58 +0100
committerChristian Segundo2025-03-19 14:23:11 +0100
commit97e8f90bdd1802d4a08a5deb549fb1aa8e8d6768 (patch)
treed6eee8777fe733e8fce3afda14a46d3c3362c740
downloadosx-jiggler-97e8f90bdd1802d4a08a5deb549fb1aa8e8d6768.tar.gz
First commit
-rw-r--r--.gitignore2
-rw-r--r--Makefile19
-rw-r--r--README23
-rw-r--r--dist/com.osx-jiggler.plist16
-rw-r--r--dist/com.osx_jiggler.plist16
-rw-r--r--main.c45
6 files changed, 121 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..58caf8b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+osx-jiggler \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..61a2767
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+CC = clang
+CFLAGS = -Wall -pedantic
+LDFLAGS = -framework ApplicationServices
+PROGRAM = osx-jiggler
+SOURCES = main.c
+OBJECTS = $(SOURCES:.c=.o)
+PREFIX = /usr/local/bin
+
+$(PROGRAM): $(OBJECTS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
+install: $(PROGRAM)
+ install -m 755 $(PROGRAM) $(PREFIX)
+
+clean:
+ -rm -f $(PROGRAM) $(OBJECTS)
diff --git a/README b/README
new file mode 100644
index 0000000..12bcfad
--- /dev/null
+++ b/README
@@ -0,0 +1,23 @@
+OSX Jiggler
+===========
+
+Prevents sleeping by simulating cursor movement. Useful in enterprisy
+environments where sleep settings are org managed.
+
+Installation
+============
+
+1. Clone or download the source code
+
+2. Run 'make' to compile the program
+
+3. Run 'sudo make install' to install the binary to '/usr/local/bin'
+or 'make install PREFIX=/custom/path' if you want to install in a
+different location.
+
+4. Run 'osx-jiggler'
+
+5. Optionally, to autostart 'osx-jiggler' you can copy the included
+launch agent and start it right away by running:
+ cp dist/com.osx_jiggler.plist ~/Library/LaunchAgents/ && \
+ launchctl load ~/Library/LaunchAgents/com.osx_jiggler.plist \ No newline at end of file
diff --git a/dist/com.osx-jiggler.plist b/dist/com.osx-jiggler.plist
new file mode 100644
index 0000000..9fbbbe4
--- /dev/null
+++ b/dist/com.osx-jiggler.plist
@@ -0,0 +1,16 @@
+<?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.osx_jiggler</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/local/bin/osx-jiggler</string>
+ </array>
+ <key>KeepAlive</key>
+ <true/>
+ <key>RunAtLoad</key>
+ <true/>
+</dict>
+</plist>> \ No newline at end of file
diff --git a/dist/com.osx_jiggler.plist b/dist/com.osx_jiggler.plist
new file mode 100644
index 0000000..9fbbbe4
--- /dev/null
+++ b/dist/com.osx_jiggler.plist
@@ -0,0 +1,16 @@
+<?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.osx_jiggler</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/local/bin/osx-jiggler</string>
+ </array>
+ <key>KeepAlive</key>
+ <true/>
+ <key>RunAtLoad</key>
+ <true/>
+</dict>
+</plist>> \ No newline at end of file
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..096f25b
--- /dev/null
+++ b/main.c
@@ -0,0 +1,45 @@
+#include <ApplicationServices/ApplicationServices.h>
+
+int main(int argc, char *argv[]) {
+ double inactivity_threshold = 60.0;
+ int right = 0;
+
+ if (argc > 1) {
+ if (strcmp(argv[1], "--help") == 0) {
+ printf("Usage: osx-jiggler [inactivity_threshold]\n");
+ printf(" inactivity_threshold: Time in seconds before the mouse moves "
+ "(default: 60.0)\n");
+ printf(" --help: Show this help message\n");
+ return 0;
+ }
+
+ inactivity_threshold = atof(argv[1]);
+ if (inactivity_threshold <= 0) {
+ fprintf(stderr,
+ "Invalid inactivity time. Please provide a positive number.\n");
+ return 1;
+ }
+ }
+
+ while (1) {
+ double idle_time = CGEventSourceSecondsSinceLastEventType(
+ kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);
+
+ if (idle_time >= inactivity_threshold) {
+ CGEventRef event = CGEventCreate(NULL);
+ CGPoint cursor = CGEventGetLocation(event);
+ CFRelease(event);
+
+ (right) ? (cursor.x += 1) : (cursor.x -= 1);
+ right = !right;
+
+ event = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, cursor,
+ kCGMouseButtonLeft);
+ CGEventPost(kCGHIDEventTap, event);
+ CFRelease(event);
+ }
+ sleep(1);
+ }
+
+ return 0;
+}