Implemented as a macOS service/quick action, or called from peripheral devices like Elgato's StreamDeck, global-go-to-line enables the "go/jump to line" feature found in code editors like Microsoft's Visual Studio Code for all line-based editing applications.
Because I hate clicking things, and I don't want carpal tunnel syndrome before I turn thirty.
The script is the functional equivalent of moving the cursor to the head position, and then repeatedly striking the ↓ key the specified number of times.
- Copy the
Go To Line.workflow
file into your user services directory:
~/Library/Services/
- In System Preferences, navigate to Security and Privacy → Privacy → Accessibility and use the ➕ button to grant the following three files permissions:
- /System/Library/CoreServices/AppleScript Utility.app
- /System/Applications/Automator.app
- /System/Applications/Utilities/Script Editor.app
-
In System Preferences, navigate to Keyboard → Shortcuts → App Shortcuts, use the ➕ button to declare a new keyboard shortcut for the menu item
"Go to Line"
.- You may define the shortcut globbaly, if you wish, but if you don't want it to override the default behavior of an app which already has Go to line functionality, you should either declare a different key combination, or scope the shortcut only to those apps in which you want functionality.
If you wish to use the service as a StreamDeck action, install the OSAScript Plugin, and then paste the contents of Go to Line.applescript
into the text field.
Though most line-based editors use the Command + ↑ key combination to move the cursor to the first line, some do not. To compensate for this, you may consider adding conditional statements to the AppleScript source such that the sent key codes correspond correctly to the application's UI. In the given files, an example is provided for the FileMaker application, which uses the key combination Option + ↑ to move the cursor:
if appname contains "FileMaker" then
key code 126 using {option down}
else
key code 126 using {command down}
end if
Should you decide to do this, keep in mind that AppleScript string comparisons are case-sensitive, and because AppleScript sucks, case shifting is not an easily-accomplished task.
Some Electron apps, like RunJS, capture all HID input when the text editor is focused. For this reason, you may be unable to define additional shortcut keys for the application. In these cases, the StreamDeck installation/setup works quite well.
Applications which offer text wrapping may not position the cursor on the exact line you specify. This is, of course, because the wrapped text adds additional lines for the cursor to traverse.
I hate AppleScript.
MIT — "Hell yeah, free software!"