Jump to content

Include version number in Workflow exports


nikivi
 Share

Recommended Posts

21 minutes ago, vitor said:

It’s just a name: if a developer wants to add the version number to it, they will


That is true. It's just a bit cumbersome to do it every time. I don't actually add version numbers myself to the exports because of this reason. But I do think there is value in knowing the version of the workflow you are downloading.

Edited by nikivi
Link to comment
Share on other sites

1 hour ago, nikivi said:

I don't actually add version numbers myself to the exports because of this reason. But I do think there is value in knowing the version of the workflow you are downloading.

 

So you’re not asking for Alfred to add the version numbers; you’re asking for other developers to do it. That’s not a problem that can be solved by Alfred, or any technical means.

Link to comment
Share on other sites

21 minutes ago, vitor said:

So you’re not asking for Alfred to add the version numbers; you’re asking for other developers to do it.

 

No I was asking for Alfred to automatically prepend version number to exports. As it is tedious to add the version number yourself.

 

 

Link to comment
Share on other sites

Here is an adapted version of the function I use to release my Workflows. Save it as workflow-packager, or something, and give it execution permissions (chmod +x workflow-packager). Then, whenever you’re in the top directory of a Workflow, in the terminal, run workflow-packager. It’ll package it up correctly — including removing variables that should not be exported — to your Desktop as Name-Version.alfredworkflow.

 

I might release it properly in another post later.

#!/bin/bash

readonly workflow_dir="$(pwd)"

if [[ "${workflow_dir}" != *'Alfred.alfredpreferences/workflows/user.workflow.'* ]] || [[ ! -f "${workflow_dir}/info.plist" ]]; then
  echo "You need to be inside the workflow’s root directory in Alfred’s preferences directory." >&2
  exit 1
fi

readonly workflow_name="$(/usr/libexec/PlistBuddy -c 'print name' "${workflow_dir}/info.plist")"
readonly workflow_version="$(/usr/libexec/PlistBuddy -c 'print version' "${workflow_dir}/info.plist")"
readonly workflow_file="${HOME}/Desktop/${workflow_name}-${workflow_version}.alfredworkflow"

find "${workflow_dir}" -iname '.DS_Store' -delete

if /usr/libexec/PlistBuddy -c 'Print variablesdontexport' "${workflow_dir}/info.plist" &> /dev/null; then
  readonly workflow_dir_to_package="$(mktemp -d)"
  cp -R "${workflow_dir}/"* "${workflow_dir_to_package}"

  readonly tmp_info_plist="${workflow_dir_to_package}/info.plist"
  /usr/libexec/PlistBuddy -c 'print variablesdontexport' "${tmp_info_plist}" | grep '    ' | sed -E 's/ {4}//' | xargs -I {} /usr/libexec/PlistBuddy -c "set variables:'{}' ''" "${tmp_info_plist}"
else
  readonly workflow_dir_to_package="${workflow_dir}"
fi

if ditto -ck "${workflow_dir_to_package}" "${workflow_file}"; then
  echo "Created ${workflow_file}"
  exit 0
else
  echo "There was and error creating ${workflow_file}" >&2
  exit 1
fi

 

Edited by vitor
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...