Debugging a do shell script command

Hi,

I’m working on a script that will act as an automation of screen share, and have reached an impasse – oh noes. The catch is that multiple options for connections are given to the user and those options are somewhat variable and need to be derived from the hostname of the computer which the script is running on. I hope that makes sense. Anyway, I’m hung up on the following:


set hostNumber to (do shell script "hostname | /usr/bin/grep -E -i -o '\-[0-9]{1,3}$' | /usr/bin/sed 's/\-//g'")

Which gives me the following error:
Expected “”" but found unknown token. (-2741)

The format of the hostname is XX-XXXX-OO where the OO is the number that I want to work with, and in theory hostNumber will be set to 00.

Hi,

backslashes must be escaped with a second backslash


set hostNumber to (do shell script "hostname | /usr/bin/grep -E -i -o '\\-[0-9]{1,3}$' | /usr/bin/sed 's/\\-//g'")

Thank you StefanK, it works perfectly now!

Ok, now I have another problem with the same script. Here it is in its entirity:


on launched theObject
	tell window 1
		set title of button "pod1" to "Connect to Pod 1"
		set title of button "pod2" to "Connect to Pod 2"
		set title of button "pod3" to "Connect to Pod 3"
		set title of button "pod4" to "Connect to Pod 4"
	end tell
end launched

on clicked theObject
	set hostNumber to (do shell script "hostname | /usr/bin/grep -E -i -o '\\-[0-9]{1,3}' | /usr/bin/sed 's/\\-//g'")
	hostNumber as integer
	if name of theObject = "pod1" then
		set hostNumber to hostNumber - 2
		tell application "Screen Sharing"
			activate
			tell application "System Events"
				keystroke "dp-d215-" & hostNumber & ".acs.unt.edu"
				keystroke return
			end tell
		end tell
	else if name of theObject = "pod2" then
		set hostNumber to hostNumber - 1
		tell application "Screen Sharing"
			activate
			tell application "System Events"
				keystroke "dp-d215-" & hostNumber & ".acs.unt.edu"
				keystroke return
			end tell
		end tell
	else if name of theObject = "pod3" then
		set hostNumber to hostNumber + 1
		tell application "Screen Sharing"
			activate
			tell application "System Events"
				keystroke "dp-d215-" & hostNumber & ".acs.unt.edu"
				keystroke return
			end tell
		end tell
	else if name of theObject = "pod4" then
		set hostNumber to hostNumber + 2
		tell application "Screen Sharing"
			activate
			tell application "System Events"
				keystroke "dp-d215-" & hostNumber & ".acs.unt.edu"
				keystroke return
			end tell
		end tell
	end if
end clicked

Is it possible to have the Screen Sharing application hidden while its doing its thing? Also, is there a way to set the default location of the screen being shared once it is connected? Like can I have it pop up on another monitor by default.

does this work?


property indexList : {-2, -1, 1, 2}

on launched theObject
	tell window 1
		set title of button "pod1" to "Connect to Pod 1"
		set title of button "pod2" to "Connect to Pod 2"
		set title of button "pod3" to "Connect to Pod 3"
		set title of button "pod4" to "Connect to Pod 4"
	end tell
end launched

on clicked theObject
	set hostNumber to (do shell script "hostname | /usr/bin/grep -E -i -o '\\-[0-9]{1,3}' | /usr/bin/sed 's/\\-//g'")
	open location "vnc://dp-d215-" & hostNumber + (item ((last character of name of theObject) as integer) of indexList) & ".acs.unt.edu"
end clicked

you can directly connect to a host via screen sharing with a vnc:// URL

I get the error: “can’t make last character of name of class <> id 2 of window id 1 into type integer. (-1700)”

Edit: i get that when i click a button in the interface.

sorry:


.
on clicked theObject
   set hostNumber to (do shell script "hostname | /usr/bin/grep -E -i -o '\\-[0-9]{1,3}' | /usr/bin/sed 's/\\-//g'")
   open location "vnc://dp-d215-" & hostNumber + (item ((last character of (get name of theObject)) as integer) of indexList) & ".acs.unt.edu"
end clicked
.

if this does not work, append .local at the end of the URL

It works like a charm! You are a gentleman and a scholar.

btw: take a look at my menulet ScreenSharingMenulet