Jump to content

Alfred's AppleScript "action" command doesn't take file objects [Improved 4.1.1 b1168 pre-release]


lilyball

Recommended Posts

If I write an Automator Apple Script action like

on run {input, parameters}
	tell application id "com.runningwithcrayons.Alfred" to action input
	return input
end run

where the input is files (either Service inputs, or the results of "Get Specified Finder Items"), Alfred opens the browse panel but with the garbage input that looks like

file:/slash/separate/path%20with%20percent%20encoding.txt

I can instead pass `POSIX PATH of input` and that works, but only for one file. I'm not sure how to convert a list of files into a list of paths in AppleScript. Thankfully I can do this with JavaScript instead, but the Apple Script support really should handle Apple Script files.

Link to comment
Share on other sites

That looks like a File URL rather than AppleScript (Finder) file object. It's unlikely I'll update Alfred to accept anything other than type text as the input argument, but I will make Alfred aware of these File URL strings.

Link to comment
Share on other sites

1 hour ago, Andrew said:

That looks like a File URL rather than AppleScript (Finder) file object

 

Automator actually gives you aliases. All you need to do is convert them to POSIX path and Alfred works fine.

 

18 hours ago, lilyball said:

I'm not sure how to convert a list of files into a list of paths in AppleScript

 

Like so:

on run {input, parameters}
    set _paths to {}
    repeat with _alias in input
        set the end of _paths to POSIX path of _alias    
    end repeat
    tell application id "com.runningwithcrayons.Alfred" to action _paths
    return input
end run

 

Link to comment
Share on other sites

You're welcome.

 

2 hours ago, lilyball said:

It would be nice if Alfred could simply handle whatever file type that Apple Script uses by default.

 

There is no AppleScript default. It depends entirely on which application or API you're getting the files from. Sometimes you get an alias, sometimes you get a file, sometimes you get a POSIX file, sometimes a POSIX path.

Link to comment
Share on other sites

Just now, lilyball said:

What I'm getting it from is an Automator workflow set up as a Service.

 

I know. That's exactly what I posted the code for.

 

1 minute ago, lilyball said:

Both file input to the service, as well as the "Get Selected Finder Items" Automator action, seem to be producing these same objects.

 

In Automator, yeah. You're duplicating a built-in feature of Alfred, so I'm sure you can understand that this isn't how Alfred's AppleScript API is typically used.

Link to comment
Share on other sites

  • 3 weeks later...

In the 4.1.1 pre-release, Alfred will now interpret file: URL strings, so you may see better behaviour here.

 

Essentially, Dean has correctly summarised this situation, and it's unlikely Alfred will accept arbitrary types here.

Link to comment
Share on other sites

  • Andrew changed the title to Alfred's AppleScript "action" command doesn't take file objects [Improved 4.1.1 b1168 pre-release]

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...