use file or folder as input into applescript

744 views
Skip to first unread message

yoose

unread,
Jan 1, 2012, 4:33:34 AM1/1/12
to Blacktree: Quicksilver
Hi, i want to be able to use a file or folder as input to an
applescript much like how text can be used, but do not see it in the
action list for "files and folders". for my current purpose, having
the path is good enough for me, so I can use the "Get Absolute (POSIX)
Path" action, but that does not allow an action afterwards to follow
so I have to execute that and then take the result and feed it into
the applescipt. so i was wondering if it is possible to make it so i
can use a file/folder as an input to applescript where it takes the
POSIX path as text or if actions in the second pane that produce text
can have a third pane option to process that text. thanks.

Daniel

unread,
Jan 2, 2012, 8:29:47 PM1/2/12
to Blacktree: Quicksilver
It would be pretty cool if QS supported some sort of action chaining,
via a shortcut like ctrl-tab or something, similar to ctrl-return.
Actually I have an idea how to implement it—a "process result..."
action that takes a QS command (from ctrl-return) in the first pane
and an action in the 3rd pane. Probably difficult to support 3-pane
actions as the second item in the chain, though...

Fortunately for you, AppleScript actions can take a file as input
directly using "on open theFile", and then get the path using "(quoted
form of POSIX path of theFile)". For instance, my script to convert a
plist to XML format is:

on open thePlist
do shell script "plutil -convert xml1 " & (quoted form of POSIX path
of thePlist)
return thePlist
end open

Lots of other cool stuff can be done this way—for instance I was just
inspired to make a "Make Burn Folder" and "Unmake Burn Folder" script
pair. "Encode"/"Decode URL" is also useful.

yoose

unread,
Jan 2, 2012, 10:59:51 PM1/2/12
to Blacktree: Quicksilver
thanks Daniel, I realize that applescript can take files and folders
as inputs, but the trouble i am having here is that runing an
applescript is not an option in the second pane when i have a file or
folder in the first pane.

Jon Stovell

unread,
Jan 3, 2012, 12:10:51 AM1/3/12
to Blacktree: Quicksilver
All you need to do is include the on open handler in your script, and
then save it in ~/Library/Application Support/Quicksilver/Actions

on open inputFiles
-- insert code to process the input files here
end open

Bryan

unread,
Apr 17, 2012, 8:38:06 AM4/17/12
to blacktree-...@googlegroups.com
Hi Jon -- I tried your suggestion and couldn't get this to work. I saved the script MyScript.scpt into the Actions folder, with the content,

using terms from application "Quicksilver"
on open inputFiles
set myFilePath to POSIX path of (path to inputFiles) as string
display dialog myFilePath
end open
end using terms from

Called a file in the first pane, tabbed to MyScript, hit enter, nothing happens. Can anyone else get this to work?

Jon Stovell

unread,
Apr 17, 2012, 12:53:17 PM4/17/12
to blacktree-...@googlegroups.com
For the on open handler, you don't need the using terms from handler.

Bryan

unread,
Apr 17, 2012, 4:34:28 PM4/17/12
to blacktree-...@googlegroups.com
Ok, I tried the following script:

on open inputFiles
set myFilePath to POSIX path of (path to inputFiles) as string
display dialog myFilePath
end open

That didn't do anything either. Sorry if I'm missing something obvious -- any ideas?

Bryan

philostein

unread,
Apr 17, 2012, 6:15:14 PM4/17/12
to blacktree-...@googlegroups.com
Change
set myFilePath to POSIX path of (path to inputFiles) as string
to
set myFilePath to POSIX path of inputFiles

- if it's one file.

Bryan

unread,
Apr 17, 2012, 6:44:28 PM4/17/12
to blacktree-...@googlegroups.com
Oh my! That worked perfectly! Many thanks Philostein.

Bryan
Reply all
Reply to author
Forward
0 new messages