How can I launch OS X's ScreenSharing from the command line and have it connect to a specified system?
Asked
Active
Viewed 1.4k times
2 Answers
28
open vnc://server.address[:port]
Scott
- 5,853
- 1
- 21
- 33
-
3open vnc://user@pass:server:port also works if you want to pass in some credentials. The security risks of doing this is yours to consider. – Ben Walding Apr 28 '12 at 05:16
-
2`open vnc://user@server:port` is also useful and doesn't have the security risks associated with having your password show up in the process list – Michael Jan 23 '13 at 15:18
-
1I never thought to type `man open` before today. It can do a lot. – Michael Fox Jan 12 '16 at 18:59
-
3Correct syntax to use password is `vnc://user:password@server:port` – levsa Oct 27 '16 at 08:47
-
Know of a way to use the VNC password as an argument to this? Thanks – Peter Becich Feb 08 '17 at 22:57
-
@PeterBecich You are funny. You put your question exactly under that comment that **answers** your questions. – GhostCat Apr 12 '18 at 12:20
-
What also works is `vnc://:password@server:port` --- meaning when you dont have a user name, but a password (our vnc servers are configured like that). – GhostCat Apr 12 '18 at 12:21
-
I want to do this and monitor for when screen sharing closes. That's not possible with `open`. – deed02392 Jan 23 '19 at 11:14
-
If you’ve already connected via Screen Sharing and allowed it to save your password (by ticking “Remember this password in my keychain”), you can use `open vnc://@server` to connect with the stored password, so you don’t have to press the Connect button. – jamesnotjim Jul 02 '19 at 14:29
2
If you have access for assistive devices activated in System Preferences, you can try saving the following AppleScript in AppleScript Editor and executing it via command line:
tell application "Screen Sharing"
activate # start Screen Sharing if not running yet
tell application "System Events"
keystroke "a" using command down # this will cause the address to clear
keystroke "127.0.0.1" # replace with your host
key code 36 # press enter
end tell
end tell
Save as Sharing.scpt, and execute as osascript /path/to/Sharing.scpt.
Daniel Beck
- 109,300
- 14
- 287
- 334