QS Action: GoToQS

16 views
Skip to first unread message

elspub

unread,
Oct 15, 2009, 8:35:17 PM10/15/09
to Blacktree: Quicksilver
Description:
GoToQS attempts to add some command line punch to QS. It started as an
alternative to Finder's GoTo function, but now includes aliases
(typing "l/as/quicksilver" takes you to "~/Library/Application Support/
Quicksilver"), sending commands to Terminal, Google and Yubnub
websearching, and launching and killing of applications. All of this
happens in QS's text entry mode.
This isn't a replacement for QS, sometimes you just want to type in
a command into a textfield and go...
Save to:
~/Library/Application Support/Quicksilver/Actions
I recommend, after installing, opening up QS preferences,
go to Actions in the sidebar
select Text in the Type list
find GoToQS and drag it as high as you want. I recommend the highest
priority for text.

To use:
type in a posix path to go there. i.e. ~/Documents will go to your
Documents Folder.
type a google search followed by a "g" to search google i.e. "poodles
g"
type a terminal command followed by a "t" to run it. i.e. "ps -ax t"
and more see the aliases key at the bottom...

Code (you can also download and read more about this here: http://tr.im/BWsr
:
using terms from application "Quicksilver"
on process text qtxt
my mainprogram(qtxt)
end process text
end using terms from
on mainprogram(qtxt)
set thePath to qtxt as string
set chCt to count characters of thePath
if chCt > 0 then
set charLst to my getChars(thePath, "rev", 2)
if charLst is equal to " y" then
set ybCt to count characters of thePath
set shYb to characters 1 thru (ybCt - 1) of thePath as string
set theURL to "http://www.yubnub.org/parser/parse?command=" & shYb
as text
tell application "System Events"
open location theURL
end tell
else if charLst is equal to " g" then
set gCt to count characters of thePath
set shG to characters 1 thru (gCt - 1) of thePath as string
set theURL to "http://www.google.com/search?hl=en&source=hp&q=" &
shG as text
tell application "System Events"
open location theURL
end tell
else if charLst is equal to " o" then
set gCt to count characters of thePath
set shA to characters 1 thru (gCt - 1) of thePath as string
if "/" is not in shA then
set shA to "a/" & shA
end if
set {shA, charOne} to aliaschk(shA, (count of shA))
set shA to "open " & quoted form of (shA & ".app")
tell application "System Events"
do shell script shA
end tell
else if charLst is equal to " q" then
set gCt to count characters of thePath
set shQ to characters 1 thru (gCt - 1) of thePath as string
do shell script "ps -ax | grep " & shQ & " | pbcopy"
set t to (the clipboard as text)
set AppleScript's text item delimiters to " "
set pidList to every text item of t
set AppleScript's text item delimiters to ""
set pid to ""
repeat with i from 1 to count of pidList
set pid to item i of pidList
if pid is not "" then
exit repeat
end if
end repeat
do shell script "kill -9 " & pid
else if charLst is equal to " t" then
set qCt to count characters of thePath
set pathTwo to characters 1 thru (qCt - 1) of thePath as string
set AppleScript's text item delimiters to " "
set pathList to text items of pathTwo as list
set AppleScript's text item delimiters to ""
set newPath to ""
repeat with i from 1 to count of pathList
set temp to item i of pathList as string
if "/" is in temp then
set {temp, charOne} to aliaschk(temp, (count of temp))
set temp to quoted form of temp
end if
if newPath is "" then
set newPath to temp as string
else
set newPath to newPath & " " & temp as string
end if
end repeat
tell application "Terminal"
activate
if front window exists then
do script newPath in front window
else
do script newPath
end if
end tell
else
set {pathTwo, charOne} to aliaschk(thePath, chCt)
set newPath to pathTwo as POSIX file
tell application "Finder"
set newWin to make new Finder window to home
try
set target of newWin to newPath
end try
if charOne is equal to "1" then
set current view of newWin to list view
else if charOne is equal to "3" then
set current view of newWin to icon view
else if charOne is equal to "2" then
set current view of newWin to column view
end if
activate
end tell
end if
end if
end mainprogram
on aliaschk(thePath, chCt)
set myPath to (POSIX path of (path to home folder))
set charOne to my getChars(thePath, 1, 2)
set char2 to my getChars(thePath, 1, 5)
if ("~" is 1st character of charOne) then
set pathTwo to replaceText(myPath, thePath, chCt, (count of
charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "1"
else if ("d" is 1st character of charOne) then
if charOne is equal to "dw" then
set pathTwo to replaceText(myPath & "Downloads", thePath, chCt,
(count of charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "2"
else if charOne is equal to "db" then
set pathTwo to replaceText(myPath & "Dropbox", thePath, chCt,
(count of charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "2"
else if charOne is equal to "dd" then
set pathTwo to replaceText(myPath & "Documents", thePath, chCt,
(count of charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "2"
else
set pathTwo to replaceText(myPath & "Desktop/", thePath, chCt,
(count of charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "3"
end if
else if ("a" is 1st character of charOne) then
--set pathTwo to "/Applications/" as text
set pathTwo to replaceText("/Applications/", thePath, chCt, (count
of charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "1"
else if ("u" is 1st character of charOne) then
set pathTwo to replaceText("/Applications/Utilities/", thePath,
chCt, (count of charOne)) as text
set newPath to pathTwo as POSIX file
set charOne to "1"
else if ("l" is 1st character of charOne) then
if ("l/as" is in char2) then
set pathTwo to replaceText(myPath & "Library/Application Support/",
thePath, chCt, (count of char2)) as text
else if ((char2 is "l/sc") or (char2 is "l/sc/") or (char2 is "l/
scr")) then
set pathTwo to myPath & "Library/Scripts/" as text
else if ((char2 is "l/se") or (char2 is "l/se/") or (char2 is "l/
ser")) then
set pathTwo to myPath & "Library/Services/" as text
else
set pathTwo to replaceText(myPath & "Library/", thePath, chCt,
(count of charOne)) as text
end if
set newPath to pathTwo as POSIX file
set charOne to "2"
else if ((charOne is "/l") and ("/Lib" is not in char2)) then
if char2 is "/l/as" then
--display dialog char2 & " and " & thePath
set pathTwo to replaceText("/Library/Application Support", thePath,
chCt, (count of char2)) as text
else
set pathTwo to replaceText("/Library/", thePath, chCt, 2) as text
end if
set newPath to pathTwo as POSIX file
set charOne to "2"
else
set charOne to "1"
set pathTwo to thePath
end if
if last character of pathTwo is " " then
set pathTwo to my getChars(pathTwo, "till", 1)
end if
return {pathTwo, charOne}
end aliaschk
on replaceText(replace, subject, ct, dex)
set eCt to dex + 1
if ct is equal to dex then
set subject to replace
else
set endSub to characters eCt thru ct of subject as string
set subject to replace & endSub
end if
return subject
end replaceText
on getChars(str1, num1, num2)
set strCt to count characters of str1
if strCt > 1 then
if (num1 is "rev") then
set num1 to strCt - (num2 - 1)
if num1 < 1 then
set num1 to 1
end if
set num2 to strCt
else if (num1 is "last") then
set num1 to strCt
set num2 to strCt
else if num1 is "till" then
set num1 to 1
set num2 to strCt - num2
end if
if num2 is "last" then
set num2 to strCt
end if
if strCt ≥ num2 then
set str2 to characters num1 thru num2 of str1 as string
else if strCt ≥ num1 then
set num2 to strCt
set str2 to characters num1 thru num2 of str1 as string
else
set str2 to str1
end if
else
set str2 to str1
end if
return str2
end getChars




superGoTo shortcuts key
Type these aliases at the beginning of your goto command. you can
build off them as well. So for example "~" goes to your home folder
and "~/documents" goes to your Documents folder.
~ goes to your home folder
d goes to your desktop
dd goes to your documents folder
dw goes to your downloads folder
db goes to your Dropbox (if you have Dropbox installed. Otherwise
you'll go Home)
a goes to your Applications folder
u goes to your Utilities folder (in Applications)
l goes to your Home's Library folder
l/as goes to Application Support in your Home's Library
l/sc goes to the Scripts folder in your Home's Library
l/se goes to the Services folder in your Home's Library

Type these command modifiers at the end of your goTo command to use
Terminal, Google, or Yubnub. Make sure there's at least one space
between the command and the modifier. So for example "poodles g" will
google search for poodles and "ps -ax t" will run "ps -ax" in the
Terminal.

o open an application at a given path. The default path is your
Applications folder. So "Mail o" will open Mail.
"o" Can be combined with the path aliases above. So "a/Mail o",
and "u/Activity Monitor o" will open Activity Monitor.
q will kill an application. so "Safari q" will kill Safari. Only use
the name of an application here.
g Google Search
t Terminal command (can be combined with the path aliases above. so
"cd dw" will run "cd Users/Downloads" at the terminal).
y yubnub (for more info on yubnub go to www.yubnub.org)

elspub

unread,
Oct 16, 2009, 2:30:08 AM10/16/09
to Blacktree: Quicksilver
Made a few changes, fixes, and improvements. You can now run shell
scripts in the background, among others...
Here is where the most up to date versions will be: http://tr.im/BY1k
Reply all
Reply to author
Forward
0 new messages