Alfred Workflow - Obtain App ID Quickly
Sometimes, retrieving an app’s ID or version information on a Mac can be inefficient if you manually check and copy it via Finder. Therefore, I used Alfred’s Universal action to achieve a one-click retrieval.
Screenshot
Pressing Enter copies it directly to the clipboard.
Principle
AppleScript can quickly obtain the version/ID information of a specified app.
1
2set appId to name of application "/Users/alanhe/Applications/JetBrains Toolbox/WebStorm.app"
copy appId to stdoutYou can find out what specific attributes can be obtained here.
MacOS comes with a Ruby/Python environment, so both can be used to read apps in the Applications directory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23require 'json'
require 'open3'
require 'pathname'
apps = Pathname('/Applications').children
.concat(Pathname('/Applications/Utilities').children)
.map(&:to_path)
.sort_by { |p| File.basename(p).downcase }
.select { |e| e.end_with?('.app') }
script_filter_items = apps.map do |app|
app_id_command = "osascript -e 'id of application \"#{app}\"'"
app_version_command = "osascript -e 'version of application \"#{app}\"'"
id_output, id_status = Open3.capture2(app_id_command)
version_output, version_status = Open3.capture2(app_version_command)
{
title: File.basename(app, '.app'),
subtitle: "ID: #{id_output.strip}, Version: #{version_output.strip}",
arg: id_output.strip,
}
end
puts JSON.generate({ items: script_filter_items })Combine Alfred’s workflow to achieve the effect.
Steps
Create a new Alfred workflow.
Add a “Universal Action” input to receive the selected application path.
Add a “Run Script” action to process the selected app using Ruby or Python.
Use
clipboard
action to copy the result to the clipboard.
1 | import subprocess |
- Test and optimize as needed.
At the end
By using Alfred’s powerful workflow and macOS scripting capabilities, you can streamline the process of retrieving application details like App ID and version. This saves time and ensures accuracy and consistency in handling app information.