Adam Stewart
Adam Stewart

Reputation: 2149

Add mark to Terminal in background using AppleScript

The macOS Terminal has a nice "mark" feature that allows you to jump between prompts using Cmd+Up/Down. I'm trying to insert my own "marks" from inside of a Python script so that I can jump to specific parts of the output (example).

Thanks to Armin Briegel, I have:

osascript -e 'tell app "System Events" to keystroke "u" using command down'

This works, but has a few problems. It doesn't add a "mark" if the Terminal is not in focus. Also, it triggers the Terminal bell alert if the Terminal is not in focus. Any way to improve this?

Upvotes: 0

Views: 147

Answers (1)

wch1zpink
wch1zpink

Reputation: 3142

Use this to bring Terminal into focus first.

osascript -e 'tell application "System Events" to tell its application process "Terminal" to set frontmost to true'

Upvotes: 1

Related Questions