Jump to content

Help passing (another) query to AppleScript


Recommended Posts

I'm sure I didn't have these problems with Alfred 1 :(
 
I've tried NSAppleScript, Run Script with osascript and pretty much every variation I can think of, but still can't get this to pass the app selected in Alfred to work with this AppleScript.
 
Is it documented somewhere explaining in more details how to pass queries from Alfred to AppleScript? I've tried looking on http://support.alfredapp.com but the content is unfinished.
 

 

Here's the original script I'm trying to make a workflow of that works in Finder (I'd like to select an app in Alfred, hit Tab and select the workflow as an action).
 

tell application "Finder" to set theApp to item 1 of (get selection)

 

set appID to id of theApp

set the clipboard to appID

 

display dialog quoted form of appID & space & "copied to the clipboard" giving up after 3

 
 
 
 
Edited by Jono
Link to comment
Asking for Finder's selection will return an "application file" object, "folder" object or "document file" object (or a combination), depending on what's selected.
 
Alfred gives your script a "text" object (i.e. the POSIX path to the selected app).
 
You have to turn that "text" object into an "application file" object to grab its id.
 
 
Using NSAppleScript:
on alfred_script(q)
	set theFile to POSIX file q
	tell application "Finder"
		set theApp to application file theFile
		set theId to id of theApp
		display dialog "ID of application " & theApp & " : " & theId
	end tell
end alfred_script

Having to change object classes all the time is one of the things I dislike most about AppleScript, and there are a lot of things I dislike about it …

 

It's a good habit to log the objects you're working with so you know what kind of objects they are. In AppleScript Editor, just do log theObject, and it will show up in the Events/Replies pane at the bottom.

Edited by deanishe
Link to comment

You came to my rescue, again  :D

 

 

 

 

Asking for Finder's selection will return an "application file" object, "folder" object or "document file" object for files etc.).

Alfred gives your script a "text" object (i.e. the POSIX path to the selected app).

You have to turn that "text" object into an "application file" object to grab its id.

 

Ah, thanks for the explanation. That's why I couldn't get it to work.

 

 

 

 

It's a good habit to log the objects you're working with so you know what kind of objects they are. In AppleScript Editor, just do log theObject, and it will show up in the Events/Replies pane at the bottom.

 

I'll do that from now on. Thanks again!

 

Link to comment

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...