Skip to content

Commit

Permalink
Add OneUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-pennyworth committed Jun 14, 2021
1 parent 0dd0ad2 commit 4ea0745
Showing 1 changed file with 131 additions and 3 deletions.
134 changes: 131 additions & 3 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,123 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>2</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>cs</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string># THESE VARIABLES MUST BE SET. SEE THE ONEUPDATER README FOR AN EXPLANATION OF EACH.
readonly remote_info_plist='https://raw.githubusercontent.com/mr-pennyworth/alfred-cleanshot/main/info.plist'
readonly workflow_url='https://github.com/mr-pennyworth/alfred-cleanshot/releases/latest/download/CleanShot.alfredworkflow'
readonly download_type='direct'
readonly frequency_check='7'
# FROM HERE ON, CODE SHOULD BE LEFT UNTOUCHED!
function abort {
echo "${1}" &gt;&amp;2
exit 1
}
function url_exists {
curl --silent --location --output /dev/null --fail --range 0-0 "${1}"
}
function notification {
local -r notificator="$(find . -type d -name 'Notificator.app')"
if [[ -n "${notificator}" ]]; then
"${notificator}/Contents/Resources/Scripts/notificator" --message "${1}" --title "${alfred_workflow_name}" --subtitle 'A new version is available'
return
fi
local -r terminal_notifier="$(find . -type f -name 'terminal-notifier')"
if [[ -n "${terminal_notifier}" ]]; then
"${terminal_notifier}" -title "${alfred_workflow_name}" -subtitle 'A new version is available' -message "${1}"
return
fi
osascript -e "display notification \"${1}\" with title \"${alfred_workflow_name}\" subtitle \"A new version is available\""
}
# Local sanity checks
readonly local_info_plist='info.plist'
readonly local_version="$(/usr/libexec/PlistBuddy -c 'print version' "${local_info_plist}")"
[[ -n "${local_version}" ]] || abort 'You need to set a workflow version in the configuration sheet.'
[[ "${download_type}" =~ ^(direct|page|github_release)$ ]] || abort "'download_type' (${download_type}) needs to be one of 'direct', 'page', or 'github_release'."
[[ "${frequency_check}" =~ ^[0-9]+$ ]] || abort "'frequency_check' (${frequency_check}) needs to be a number."
# Check for updates
if [[ $(find "${local_info_plist}" -mtime +"${frequency_check}"d) ]]; then
if ! url_exists "${remote_info_plist}"; then abort "'remote_info_plist' (${remote_info_plist}) appears to not be reachable."; fi # Remote sanity check
readonly tmp_file="$(mktemp)"
curl --silent --location --output "${tmp_file}" "${remote_info_plist}"
readonly remote_version="$(/usr/libexec/PlistBuddy -c 'print version' "${tmp_file}")"
if [[ "${local_version}" == "${remote_version}" ]]; then
touch "${local_info_plist}" # Reset timer by touching local file
exit 0
fi
if [[ "${download_type}" == 'page' ]]; then
notification 'Opening download page…'
open "${workflow_url}"
exit 0
fi
download_url="$([[ "${download_type}" == 'github_release' ]] &amp;&amp; curl --silent "https://api.github.com/repos/${workflow_url}/releases/latest" | grep 'browser_download_url' | head -1 | sed -E 's/.*browser_download_url": "(.*)"/\1/' || echo "${workflow_url}")"
if url_exists "${download_url}"; then
notification 'Downloading and installing…'
curl --silent --location --output "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow" "${download_url}"
open "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow"
else
abort "'workflow_url' (${download_url}) appears to not be reachable."
fi
fi</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string></string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>8C4555D0-460A-4EA7-ADFF-BA9C3BACDCD8</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -708,6 +825,19 @@
<key>ypos</key>
<integer>225</integer>
</dict>
<key>8C4555D0-460A-4EA7-ADFF-BA9C3BACDCD8</key>
<dict>
<key>colorindex</key>
<integer>12</integer>
<key>note</key>
<string>OneUpdater: keep this workflow updated
Check for updates: once a week</string>
<key>xpos</key>
<integer>10</integer>
<key>ypos</key>
<integer>10</integer>
</dict>
<key>B0B38CAD-6949-4F11-9B8E-B53F7538F5EB</key>
<dict>
<key>xpos</key>
Expand All @@ -723,10 +853,8 @@
<integer>10</integer>
</dict>
</dict>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.1.1</string>
<string>0.1.2</string>
<key>webaddress</key>
<string>https://github.com/mr-pennyworth/alfred-cleanshot</string>
</dict>
Expand Down

0 comments on commit 4ea0745

Please sign in to comment.