Skip to content

Instantly share code, notes, and snippets.

@husniadil
Last active February 19, 2025 03:44
Show Gist options
  • Select an option

  • Save husniadil/b207227c31ff8a26e03bf00c3a53ebfd to your computer and use it in GitHub Desktop.

Select an option

Save husniadil/b207227c31ff8a26e03bf00c3a53ebfd to your computer and use it in GitHub Desktop.
Run Cursor Composer from Terminal

This is how to run Cursor Composer from Terminal

image

Save this into a file, e.g.: cursor_prompt.scpt using Apple's Script Editor.

on run argv
	if (count of argv) is 0 then
		return
	end if
	set userPrompt to item 1 of argv
	
	-- Check if Cursor is running
	if application "Cursor" is not running then
		tell application "Cursor" to launch
		delay 2
	end if
	
	-- Check if Cursor is frontmost
	tell application "System Events"
		if not (exists process "Cursor") or not (frontmost of process "Cursor") then
			tell application "Cursor" to activate
			delay 1
		end if
	end tell
	
	-- Check if there's an existing window before creating new one
	tell application "System Events"
		tell process "Cursor"
			if not (exists window 1) then
				keystroke "n" using command down
				delay 1
			end if
		end tell
	end tell
	
	-- Wait for Cursor window to appear and be ready
	tell application "System Events"
		repeat until (exists window 1 of process "Cursor")
			delay 0.5
		end repeat
		-- Additional delay to ensure UI is fully responsive
		delay 1.5
	end tell
	
	tell application "System Events"
		tell process "Cursor"
			-- Simulate Tab
			keystroke tab
			delay 0.5
			
			-- Simulate Command + I
			keystroke "i" using command down
			delay 0.5
			
			-- Paste the prompt
			set the clipboard to userPrompt
			keystroke "v" using command down
		end tell
	end tell
end run

Make sure it is executable:

chmod +x cursor_prompt.scpt

Run it:

osascript cursor_prompt.scpt "Write a Python function that calculates the fibonacci sequence"

You can use and modify it as you need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment