Page 1 of 1

How to have an action return a selection of files

Posted: Mon Jul 14, 2014 5:30 pm
by nikjft
I'm trying to build an action that will list all the scripts specific to a certain application. The problem I'm having is that when I set a selection, it's just a bunch of aliases, not actual files. I could go through and create children, but when I do that, I end up with roughly the same thing unless I do quite a bit of heavy lifting to create follow-up actions based on the type of file returned.

Is there a way to simply provide individual files as children or as a selection so that the returned scripts can be run, have their handle_string handler utilized, etc.?

Thanks!

My current script is as follows:

Code: Select all

property indexedFileTypes : {"Script", "Application", "Text"}
property indexedFileExtensions : {"app", "scpt", "applescript", "rb", "py", "sh", "pl", "bash"}

on run
   
   set appScripts to {}
   tell application "System Events" to set appProc to name of first application process whose frontmost is true and visible is true
   
   tell application "Finder"
      
      try
         get path to scripts folder from user domain
         get folder appProc of folder "Applications" of result as alias
         set localFiles to (files of (entire contents of result) whose name extension is in indexedFileExtensions or kind is in indexedFileTypes) as alias list
         
         set appScripts to appScripts & localFiles
         
      end try
      
      try
         get path to scripts folder from local domain
         get folder appProc of folder "Applications" of result as alias
         set localFiles to (files of (entire contents of result) whose name extension is in indexedFileExtensions or kind is in indexedFileTypes)
         set appScripts to appScripts & localFiles
      end try
   end tell
   
   
   tell application "LaunchBar"
      
      if (count of appScripts) > 0 then
         set selection as list to appScripts
      else
         display in large type "There are no application-specific scripts for " & appProc & "."
      end if
   end tell
   
end run

Re: How to have an action return a selection of files

Posted: Tue Jul 15, 2014 5:44 am
by iRounak
Post you problem at http://www.macscripter.net
The site is very helpful especially to newbies.

Once you get your answers there, then you can refer to LB specific info here:

http://www.obdev.at/resources/launchbar ... ion-output


PS: It is possible to return a selection of files as you can see in many scripts in this forum like
viewtopic.php?f=24&t=9126#p27489

Re: How to have an action return a selection of files

Posted: Tue Jul 15, 2014 7:00 pm
by Nik
Thanks, but the script is working fine and returns a list of files. However, those files are literally just paths - they do not display as nor behave as a list of files. See screenshot of what the script returns:

Image

The question is how do I get this to behave as actual files rather than just a list of URL paths?

Re: How to have an action return a selection of files

Posted: Wed Jul 16, 2014 3:38 am
by iRounak
The link that I posted earlier (http://www.obdev.at/resources/launchbar ... ion-output) should answer your question.

Here's an example:
https://dl.dropboxusercontent.com/u/973 ... action.zip

If this does not help, post the .lbaction file here.

Re: How to have an action return a selection of files

Posted: Wed Jul 30, 2014 2:25 am
by Nik
Turns out the missing component was the "path" variable in the returned record set. I had that set to the Mac path, but if it's a POSIX path it works.

Thanks for your help!

Re: How to have an action return a selection of files

Posted: Fri Feb 22, 2019 8:57 am
by cyqafas
An action return was needed on some selection of files that was possible on certain applications that was not actual file. I need to get the list of applications available on ukbestessays custom writing this have all the data of ODF.