alfredclough Posted March 7, 2018 Share Posted March 7, 2018 (edited) I have a workflow where I want to provide a list of applications so that an application can be selected and the workflow continue. I want a list of the current running applications so I'm using a Script Filter. My question is how can I load the icon of the app to show it in the list rather than the icon of the workflow? I can't seem to find out how to programmatically load it. Here is the AppleScript I'm using with the Script Filter: on run argv tell application "System Events" set runningProcesses to (name of every process whose background only is false) end tell set alfredJSON to "{\"items\": [" repeat with appName in runningProcesses --set appName to name of runningProcess set alfredJSON to alfredJSON & "{\"uid\": \"" & appName & "\", \"type\": \"default\", \"title\": \"" & appName & "\",\"subtitle\": \"\", \"arg\": \"" & appName & "\",\"autocomplete\": \"insert passage\"}," end repeat set alfredJSON to alfredJSON & "]}" return alfredJSON end run Edited March 7, 2018 by vitor Marked as solved Link to comment
vitor Posted March 7, 2018 Share Posted March 7, 2018 Instead of trying to get the icon with AppleScript, leverage what Alfred already gives you for free. In the JSON, set icon: { "type": "fileicon", "path": "{{path_to_app}" }. But in the future, when asking help with a Workflow please upload it somewhere. See the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report. Link to comment
alfredclough Posted March 7, 2018 Author Share Posted March 7, 2018 18 minutes ago, vitor said: Instead of trying to get the icon with AppleScript, leverage what Alfred already gives you for free. In the JSON, set icon: { "type": "fileicon", "path": "{{path_to_app}" }. I tried that and I can build the JSON when I run the AppleScript in Apple's script editor, but when I tried to run it using Alfred, I get the message: execution error: System Events got an error: Can’t get path of file of application process "Safari" Here's the AppleScript I'm running: on run argv tell application "System Events" set runningProcesses to (every process whose background only is false) end tell set alfredJSON to "{\"items\": [" repeat with runningProcess in runningProcesses set appName to name of runningProcess set appPath to path of file of runningProcess set alfredJSON to alfredJSON & "{\"uid\": \"" & appName & "\", \"type\": \"default\", \"title\": \"" & appName & "\",\"subtitle\": \"\", \"arg\": \"" & appName & "\",\"autocomplete\": \"insert passage\", \"icon\": { \"type\": \"fileicon\", \"path\":\"" & appPath & "\" }}," end repeat set alfredJSON to alfredJSON & "]}" return alfredJSON end run Here's a link to the workflow. I'm using Alfred 3.6 and Mac OS 10.13.3 Link to comment
vitor Posted March 7, 2018 Share Posted March 7, 2018 You don’t need the on run. You’ll also need to make sure you’re using POSIX paths. Try this: tell application "System Events" set runningProcesses to (every process whose background only is false) end tell set alfredJSON to "{\"items\": [" repeat with runningProcess in runningProcesses set appName to name of runningProcess set appPath to POSIX path of (file of runningProcess as alias) set alfredJSON to alfredJSON & "{\"uid\": \"" & appName & "\", \"type\": \"default\", \"title\": \"" & appName & "\",\"subtitle\": \"\", \"arg\": \"" & appName & "\",\"autocomplete\": \"insert passage\", \"icon\": { \"type\": \"fileicon\", \"path\":\"" & appPath & "\" }}," end repeat set alfredJSON to alfredJSON & "]}" return alfredJSON Link to comment
alfredclough Posted March 7, 2018 Author Share Posted March 7, 2018 Perfect--that worked. Thank you. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now