Copying Alfred's environment to your shell

A simple script to create an Alfred-like environment in your shell by extracting and exporting variables from info.plist.

Alfred uses environment variables to pass some important information to your workflow code, like the paths to the data and cache directories.

Source the following script in your shell and/or test runner to extract Alfred workflow variables from info.plist:

# When sourced, creates an Alfred-like environment

# getvar <name> | Read a value from info.plist
getvar() {
    local v="$1"
    /usr/libexec/PlistBuddy -c "Print :$v" info.plist
}

# Minimal workflow settings
export alfred_workflow_bundleid=$( getvar "bundleid" )
export alfred_workflow_name=$( getvar "name" )
# Required if you're using AwGo's built-in update mechanism
export alfred_workflow_version=$( getvar "version" )

# Standard locations of Alfred 3 cache & data directories
export alfred_workflow_cache="${HOME}/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Data/${alfred_workflow_bundleid}"
export alfred_workflow_data="${HOME}/Library/Application Support/Alfred 3/Workflow Data/${alfred_workflow_bundleid}"

# If you want to extract workflow variables set in the workflow
# configuration sheet:
# export SCHEDULE_DAYS=$( getvar "variables:SCHEDULE_DAYS" )
# export EVENT_CACHE_MINS=$( getvar "variables:EVENT_CACHE_MINS" )
New snippet on Alfred workflow environment variables
654e307