You copy the script below and create your own applescript, or just
download it here: http://tr.im/DW8q
Description:
Quicksilver script that's an alternative to its (somewhat hobbled
under Snow Leopard)get current selection function. This script will
grab whatever is selected in the current, or front most application,
and bring itinto Quicksilver. If you're in the Finder, that will be
file(s). In which case QS will activate with those files in its first
pane. If other applications, that will be text, in which case
Quicksilver will activate with that text in its text entry mode.

Where to Save:
 ~/Library/Scripts
I recommend setting this up as a trigger in QS. Then, you can select
whatever, hit your trigger, and QS will have it.
Usage:
Select files in the finder, or text in other applications, and hit
your trigger or activate QS and type till you see qsGetSel and tab
over and hit enter.
Code:

tell application "System Events" to set thsApp to name of the first
process whose frontmost is true
set g to my getSelctd(thsApp)
tell application "Quicksilver" to open g
if thsApp is not "Finder" then
        tell application "System Events" to keystroke "."
end if
on getSelctd(nxtApp)
        if nxtApp is "Finder" then
                try
                        tell application "Finder" to set thisFile to selection
                        set flCt to count of thisFile
                        if flCt > 1 then
                                set selecTxt to {}
                                repeat with i from 1 to flCt
                                        set thsFl to item i of thisFile
                                        tell application "Finder" to set 
thsAlias to thsFl as alias
                                        set end of selecTxt to POSIX path of 
thsAlias
                                end repeat
                        else
                                set selecTxt to ""
                                tell application "Finder" to set thsAlias to 
thisFile as alias
                                set selecTxt to POSIX path of thsAlias
                        end if
                        return selecTxt
                on error
                        return ""
                end try
        else
                if nxtApp is "Safari" then
                        tell application "Safari"
                                set selecTxt to (do JavaScript 
"(getSelection())" in document 1)
                        end tell
                        if (count of selecTxt) is 0 then
                                set the clipboard to ""
                                tell application "Safari" to activate
                                delay 0.12    --this number is a guess, but it 
seems a delay is
necessary to time things right
                                tell application "System Events" to key code 8 
using command down
                                delay 0.12    --this number is a guess, but it 
seems a delay is
necessary to time things from the clipboard
                                set selecTxt to (the clipboard as string)
                        end if
                else
                        set the clipboard to ""
                        tell application nxtApp to activate
                        delay 0.12    --this number is a guess, but it seems a 
delay is
necessary to time things right
                        tell application "System Events" to key code 8 using 
command down
                        delay 0.12    --this number is a guess, but it seems a 
delay is
necessary to time things from the clipboard
                        set selecTxt to (the clipboard as string)
                end if
                set selecTxt to my klWS(selecTxt)
                return (selecTxt as string)
        end if
end getSelctd
on klWS(intxt) -- will return txt without leading or trailing
whitespace
        if (count of intxt) is 0 then
                return ""
        else if (intxt is " ") then
                return ""
        else if (intxt is "  ") then
                return ""
        else
                set outxt to ""
                set outid to 0
                set k to 1
                repeat
                        set thschr to character k of intxt
                        if thschr is " " then
                                set outid to 0
                        else if thschr is "" then
                                set outid to 0
                        else
                                set outid to k
                                exit repeat
                        end if
                        if k < (count of intxt) then
                                set k to k + 1
                        else
                                set k to ""
                                exit repeat
                        end if
                end repeat
                if k > 0 then
                        set midtxt to characters k thru (count of intxt) of 
intxt as string
                else
                        return ""
                end if
                set j to count of midtxt
                repeat
                        set thschr to character j of midtxt
                        if thschr is " " then
                                set outid to 0
                        else if thschr is "" then
                                set outid to 0
                        else
                                set outid to j
                                exit repeat
                        end if
                        if j > 1 then
                                set j to j - 1
                        else
                                set j to ""
                                exit repeat
                        end if
                end repeat
                if j > 0 then
                        set outxt to characters 1 thru j of midtxt as string
                else
                        return ""
                end if
                return (outxt as string)
        end if
end klWS

Reply via email to