bcartledge1871 Posted August 4, 2013 Share Posted August 4, 2013 SecureCRT is a terminal client I use for ssh sessions. I've created a simple workflow that opens the app and passes a session name query to automatically connect to a host - /Applications/SecureCRT.app/Contents/MacOS/SecureCRT /S <Session_Name> Now this works fine but SecureCRT nests the session .ini files in folders (and I have a few hundred of these based on the device locations), so I find myself having to include the path in the keyword argument. For example "keyword \folder\host.ini". What I'd like to be able to achieve is a way of searching the folders for the host .ini and then passing the resulting path to the command line argument that launches the appropriate session in the app. Hope that makes sense and thanks in advance for any help or pointers. Link to comment
jdfwarrior Posted August 5, 2013 Share Posted August 5, 2013 SecureCRT is a terminal client I use for ssh sessions. I've created a simple workflow that opens the app and passes a session name query to automatically connect to a host - /Applications/SecureCRT.app/Contents/MacOS/SecureCRT /S <Session_Name> Now this works fine but SecureCRT nests the session .ini files in folders (and I have a few hundred of these based on the device locations), so I find myself having to include the path in the keyword argument. For example "keyword \folder\host.ini". What I'd like to be able to achieve is a way of searching the folders for the host .ini and then passing the resulting path to the command line argument that launches the appropriate session in the app. Hope that makes sense and thanks in advance for any help or pointers. Would creating a file filter potentially work for this? Since a .ini is plain text, you could create a file filter that would only search within that root directory or below, for .ini files, and you could make it search the contents to find the hostname. The only downside would be that it would search all the contents for a match. I say that's a downside but I don't know how much data is in each. Link to comment
bcartledge1871 Posted August 8, 2013 Author Share Posted August 8, 2013 (edited) Within the .ini the hostname is referenced by IP address like this - S:"Hostname"=192.168.0.1 With the field kMDItemTextContext I tried a value of "Hostname"={query} and no joy but I'm not sure thats what I'm looking for. I'd like to be able to open the sessions by name as I don't remember all the IP addresses. For example - Sessions Folder Houston Houston-router.ini Houston-switch.ini London London-router.ini London-switch1.ini ...... When using the /S switch when opening SecureCRT it can only look for a .ini in the session folder root if you don't specify the full path. kMDItemPath would would be ideal but it doesn't look like it can be used with a query? http://stackoverflow.com/questions/1341590/no-results-in-spotlight-in-searches-against-kmditempath/1342019#1342019 Edited August 8, 2013 by bcartledge1871 Link to comment
bcartledge1871 Posted September 8, 2013 Author Share Posted September 8, 2013 I was able to get somewhere with this using a file filter and some text manipulation in an NSAppleScript action. What happens though is that SecureCRT launches and connects to the host, however while its running I can't use Alfred until I quit the SecureCRT application. do shell script "/Applications/SecureCRT.app/Contents/MacOS/SecureCRT /S " & result Link to comment
bcartledge1871 Posted September 12, 2013 Author Share Posted September 12, 2013 Ok I got there in the end with the help of google. The script is below in case other SecureCRT users find it useful. It's my first attempt at Applescript so open to any suggestions or ways to simplify. One caveat is if the session name has a space it's not working. In this case the session name must be enclosed with quotation marks and I can't figure out the correct AppleScript syntax e.g. /Applications/SecureCRT.app/Contents/MacOS/SecureCRT /T /S "My Session". But as a workaround I can rename my session files and folders to remove any spaces. set findThis to "/Users/*******/******/VanDyke/Config/Sessions/" -- SecureCRT sessions path set replaceItWith to "" set newText to switchText of "{query}" from findThis to replaceItWith trim_ext(newText, ".ini") -- remove .ini extension do shell script "/Applications/SecureCRT.app/Contents/MacOS/SecureCRT /T /S " & result & " > /dev/null 2>&1 &" -- start SecureCRT to switchText of theText from SearchString to ReplaceString -- remove sessions path set OldDelims to AppleScript's AppleScript's text item delimiters set AppleScript's AppleScript's text item delimiters to SearchString set newText to text items of theText set AppleScript's AppleScript's text item delimiters to ReplaceString set newText to newText as text set AppleScript's AppleScript's text item delimiters to OldDelims return newText end switchText on trim_ext(strg, trim_characters) set trim_list to every character of trim_characters set right_counter to -1 repeat with J from 1 to length of strg if (character right_counter of strg) is in trim_list then set right_counter to right_counter - 1 else exit repeat end if end repeat try set strg to text 1 through right_counter of strg on error set strg to "" end try return strg end trim_ext Link to comment
PBear Posted March 8, 2014 Share Posted March 8, 2014 Hello, I'm very interested by ur workflow. How can I install and use it ? Can you do it as a downloadable WF ? Thank you Link to comment
PBear Posted March 10, 2014 Share Posted March 10, 2014 I found your script.workflow on the web. But it does not work. I face several problems. One is the script calling "Securecrt /T", this option is not supported (anymore?). But it's not the main problem. A big problem is the caveat you was talking about: All the sessions and directories must be without space. It's a big problem :s Is there any script expert around who could fix it ? Link to comment
bcartledge1871 Posted April 24, 2014 Author Share Posted April 24, 2014 "Securecrt /T", this option is not supported (anymore?). /T will open the session in a new tab. I think tabs where introduced in v.7, so if you have an older version remove the option All the sessions and directories must be without space. It's a big problem :s Is there any script expert around who could fix it This is a pain and I hoped to go back and fix but never seem to find the time... Link to comment
rice.shawn Posted April 25, 2014 Share Posted April 25, 2014 If there are spaces in the directory causing the script to fail, then you might just look into "the quoted form of" a variable. Look here for a bit more: http://www.satimage.fr/software/en/smile/external_codes/file_paths.html Link to comment
PBear Posted May 10, 2014 Share Posted May 10, 2014 (edited) @bcartledge1871 Any chance you fix your script with the advices of Shawn Rice ? If someone else would like to fix it too, here is the script Edited May 10, 2014 by thailoving Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now