Jump to content
Steven_

Connecting to remove server(s)

Recommended Posts

Hi

 

Firstly, this may be a feature that can be handled by the Worklows addition to Alfred, though I don't have the skills to create the required scripts...

 

I spend a large amount of my day working off Servers. Either Windows 2003/2008 or Mac OSX Server. To access the servers I use the CMD + K shortcut to access the 'Connect to server' dialog, then choose the server I want to connect to etc etc.

 

I'd really like to be able to invoke Alfred, type a keyword (maybe 'srv') along with the required server name and have that server mount and open in finder.

 

Hope that makes sense, if anyone can do this with Workflows I'd love to know how they've made it happen!

 

Cheers

 

Steven

Share this post


Link to post

Steven,

 

Since this was something that could more than likely be handled with a Workflow and isn't a request for a code Alfred feature, I moved this thread to the Workflow Creators forum.

 

Thanks

Share this post


Link to post

Hi and thanks Ken that's great!

 

I'd like to have a method of typing a abbreviation of the server name (without the smb/afp part) after srv to make it quicker. Using what you've given me and what I can find by googling aroundI'll see if I can work out the AppleScript for it.

 

Will post back here if it works.

 

Cheers

 

Steven

Share this post


Link to post

One kinda of easy thing would be to make a workflow that will allow you to add locations/servers.. So do something like 'addserver smb://HTPC' and that would save it in a list. Then use 'srv <name>' and it would show a list of saved servers to select from.

 

I can prob make it tonight it you want?

Share this post


Link to post

Hi both

 

Thanks for your help, it really is much appreciated :)

 

David, I've tried the workflow above. When I enter a server using 'addserver' I get an error message in Growl/Notification Centre. The error message is cut off due to it's length and the available space in the Notification Centre window, but it starts:

 

 New Server

Warning: array_combine(): Both parameters should have an equal number of elements...

 

Just to make sure I'm entering the data correctly, I input this into the 'addserver' workflow in Alfred:

 

'addserver afp://192.168.0.100'

 

Once again, thanks for the help 

 

Steven

Share this post


Link to post

Yeah sorry I forgot to tell you how to enter them

 

Use:

Syntax
addserver <name> <path>

Example
addserver file_server afp://127.0.0.1

 

My bad.. I added a "name" so you could have an easily recognizable name for the servers too if you wanted.. One downside to it is that it doesn't spaces in the name right now. I can fix that for you later if you'd like.

 

Let me know if you get it working

Share this post


Link to post

David - works like a charm, thanks very much for all your help.

 

I've taken a quick look at the PHP behind it, will digest over the next few days to get my head around what it's doing.

 

All the best

 

Steven

Share this post


Link to post

I'll give you a quick overview.

 

addserver -

Accepts the input and then splits it into an array based on <space> so it can grab the name and server values separately. It checks to see if servers.json exists. If so, adds the new entry to the servers list and writes it back to the json file. If the servers.json file doesn't exist, it makes a new array (the single, new server), and writes that to a new servers.json. Echos success.

 

srv -

Looks for the servers.json file. If it's there, it reads the file and formats the server list as xml for Alfred feedback. If the file doesn't exist, it returns a feedback item saying that no servers are available.

Share this post


Link to post
How do I remove servers from the list? So when I type "srv" it stops showing an unused address? 

 

Thanks

 

I didn't add that because it wasn't something that Steven_ originally asked for. I guess I could make a quick edit to remove one by typing 'srv' and in the list, highlight one and press cmd+enter. I'll try to get it posted later.

Share this post


Link to post

David,

 

I just wanted to thank you for this workflow, since it's something I've been looking for a long time. Replaced my Keyboard Maestro script instantly. 

 

/P

Share this post


Link to post

Just made a little update to this to make it so that you could remove servers from the list.

 

Just use the srv keyword to get your server list, highlight the server you want to delete, and press cmd+enter to delete it from the server list

 

Download

Share this post


Link to post
Just made a little update to this to make it so that you could remove servers from the list.

 

Just use the srv keyword to get your server list, highlight the server you want to delete, and press cmd+enter to delete it from the server list

 

Download

Man, you absolutely ROCK. At your feet :/_

Share this post


Link to post

i use this: (Keyword>Run Apple Script)

 

 

on alfred_script(q)
 tell application "Finder"
  open location "smb://username@server"
 end tell
end alfred_script

because I want to open location in Finder :)

Share this post


Link to post
It would be awesome if you could type `srv <name> <volume>` and have Alfred filter the volumes on that server as an instant search. For example, I have these volumes on my NAS:

 

http://cl.ly/image/2q101M1s2f2C

 

That would mean I could type `srv nas media` to access the Media volume on my NAS. :)

 

I have this script

 

on alfred_script(argv)
	set myList to splitString(argv, " ")
	set numItems to count myList

	if numItems is less than 3 then
		display dialog "You need to pass at least 3 arguments"
		return
	end if

	set theServer to item 1 of myList
	set theUsername to item 2 of myList
	set thePassword to item 3 of myList
	set theVolume to item 4 of myList

	set theUrl to "afp://" & theUsername & ":" & thePassword & "@" & theServer

	if numItems is 4 then
		set theUrl to theUrl & "/" & theVolume
	end if

	--display dialog theUrl

	tell application "Finder"
		mount volume theUrl
	end tell
end alfred_script

to splitString(aString, delimiter)
 set retVal to {}
 set prevDelimiter to AppleScript's text item delimiters
 log delimiter
 set AppleScript's text item delimiters to {delimiter}
 set retVal to every text item of aString
 set AppleScript's text item delimiters to prevDelimiter
 return retVal
end splitString

 

 

The only problem is that it won't work if the volume has a space in it.  I can't figure out how to escape a space when entering the query in Alfred

Share this post


Link to post
It would be awesome if you could type `srv <name> <volume>` and have Alfred filter the volumes on that server as an instant search. For example, I have these volumes on my NAS:

 

http://cl.ly/image/2q101M1s2f2C

 

That would mean I could type `srv nas media` to access the Media volume on my NAS. :)

 

I have this script

on alfred_script(argv)
	set myList to splitString(argv, " ")
	set numItems to count myList

if numItems is less than 3 then
display dialog "You need to pass at least 3 arguments"
return
end if

set theServer to item 1 of myList set theUsername to item 2 of myList set thePassword to item 3 of myList set theVolume to item 4 of myList set theUrl to "afp://" & theUsername & ":" & thePassword & "@" & theServer if numItems is 4 then set theUrl to theUrl & "/" & theVolume end if --display dialog theUrl tell application "Finder" mount volume theUrl end tell end alfred_script to splitString(aString, delimiter) set retVal to {} set prevDelimiter to AppleScript's text item delimiters log delimiter set AppleScript's text item delimiters to {delimiter} set retVal to every text item of aString set AppleScript's text item delimiters to prevDelimiter return retVal end splitString

 

 

 

 

The only problem is that it won't work if the volume has a space in it.  I can't figure out how to escape a space when entering the query in Alfred

Share this post


Link to post

Another issue with your request also would be that, if your remote location requires a password you can't grab a list of potential shares. If its wide open, it's a little easier

Share this post


Link to post

This works amazingly well.  Thanks.

 

I was hoping to figure out how to use the exact same workflow but modify it to start screen sharing sessions.  Unfortunately my php and bash knowledge are nil. 

 

Any experienced kind souls that might help?

Share this post


Link to post

Just made a little update to this to make it so that you could remove servers from the list.

 

Just use the srv keyword to get your server list, highlight the server you want to delete, and press cmd+enter to delete it from the server list

 

Download

 

Please change line 4 in addserver.php from:

 

 

$input = explode( " ", $input );
 
to:
 
$input = explode( " ", $input, 2 );
 
UNCs can have spaces in them.
 
 

Share this post


Link to post

Please change line 4 in addserver.php from:

 

 

$input = explode( " ", $input );
 
to:
 
$input = explode( " ", $input, 2 );
 
UNCs can have spaces in them.
 
 

 

Awesome, will do. I've been using explode() forever and I thought I knew the full syntax so I had never looked back to notice there was a limit parameter. I'll get this added.

 

Thanks

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...