Last active
June 26, 2020 00:11
-
-
Save humblehacker/6b8d9cb43419093648aaa06ef46fd2ac to your computer and use it in GitHub Desktop.
Given an absolute path, line number, and column number, launch Visual Studio for Mac and go there.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run {filepath, linenumber, columnnumber} | |
tell application "Visual Studio" to activate | |
tell application "System Events" | |
-- ⌘O File → Open... | |
keystroke "o" using command down | |
delay 1 | |
-- ⇧⌘G Goto file path | |
keystroke "g" using {command down, shift down} | |
delay 1 | |
-- type in filepath | |
keystroke filepath | |
delay 1 | |
-- ⏎ | |
key code 36 | |
delay 1 | |
-- ⏎ | |
key code 36 | |
delay 1 | |
-- ⌘L Search → Goto → Line... | |
keystroke "l" using command down | |
delay 1 | |
-- type in linenumber:columnnumber e.g. '17:11' | |
keystroke linenumber | |
key code 41 using shift down -- : | |
keystroke columnnumber | |
-- ⏎ | |
key code 36 | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script mostly works, but is not ideal for obvious and less obvious reasons. Obviously, driving the UI with generated keystrokes is brittle, and will break under many circumstances. Non-obviously, the use of
delay
throughout doesn't work as expected. None of these delays appear to be lasting for a second. So sometimes, the operation seems to quit half-way through, or you end up typing the line and column numbers into the file that you opened. Even more odd, sometimes the ⌘G operation gets executed twice.So use this at your own risk. If anyone comes up with a better way, please let me know.
With that said, I use this as an external tool in Jetbrains Rider. Here's how:
You can do the same thing in Visual Studio:
Unfortunately, you apparently can't use
~
or environment variables like$HOME
in the command field.