|
108 | 108 | <key>vitoclose</key>
|
109 | 109 | <false/>
|
110 | 110 | </dict>
|
| 111 | + <dict> |
| 112 | + <key>destinationuid</key> |
| 113 | + <string>7AEEE496-6258-4811-A26B-16F2133EA5C7</string> |
| 114 | + <key>modifiers</key> |
| 115 | + <integer>0</integer> |
| 116 | + <key>modifiersubtext</key> |
| 117 | + <string></string> |
| 118 | + <key>vitoclose</key> |
| 119 | + <false/> |
| 120 | + </dict> |
111 | 121 | </array>
|
112 | 122 | <key>B8C7AC3E-494B-4E67-87EE-F949A3A7D88A</key>
|
113 | 123 | <array>
|
|
440 | 450 | <key>version</key>
|
441 | 451 | <integer>1</integer>
|
442 | 452 | </dict>
|
| 453 | + <dict> |
| 454 | + <key>config</key> |
| 455 | + <dict> |
| 456 | + <key>concurrently</key> |
| 457 | + <false/> |
| 458 | + <key>escaping</key> |
| 459 | + <integer>0</integer> |
| 460 | + <key>script</key> |
| 461 | + <string># THESE VARIABLES MUST BE SET. SEE THE ONEUPDATER README FOR AN EXPLANATION OF EACH. |
| 462 | +readonly remote_info_plist="https://raw.githubusercontent.com/Acidham/alfred-image-shrinker/main/src/info.plist" |
| 463 | +readonly workflow_url="Acidham/alfred-image-shrinker" |
| 464 | +readonly download_type='github_release' |
| 465 | +readonly frequency_check='4' |
| 466 | +
|
| 467 | +# FROM HERE ON, CODE SHOULD BE LEFT UNTOUCHED! |
| 468 | +function abort { |
| 469 | + echo "${1}" >&2 |
| 470 | + exit 1 |
| 471 | +} |
| 472 | +
|
| 473 | +function url_exists { |
| 474 | + curl --silent --location --output /dev/null --fail --range 0-0 "${1}" |
| 475 | +} |
| 476 | +
|
| 477 | +function notification { |
| 478 | + readonly local notificator="$(find . -type d -name 'Notificator.app')" |
| 479 | + if [[ -n "${notificator}" ]]; then |
| 480 | + "${notificator}/Contents/Resources/Scripts/notificator" --message "${1}" --title "${alfred_workflow_name}" --subtitle 'A new version is available' |
| 481 | + return |
| 482 | + fi |
| 483 | +
|
| 484 | + readonly local terminal_notifier="$(find . -type f -name 'terminal-notifier')" |
| 485 | + if [[ -n "${terminal_notifier}" ]]; then |
| 486 | + "${terminal_notifier}" -title "${alfred_workflow_name}" -subtitle 'A new version is available' -message "${1}" |
| 487 | + return |
| 488 | + fi |
| 489 | +
|
| 490 | + osascript -e "display notification \"${1}\" with title \"${alfred_workflow_name}\" subtitle \"A new version is available\"" |
| 491 | +} |
| 492 | +
|
| 493 | +# Local sanity checks |
| 494 | +readonly local_info_plist='info.plist' |
| 495 | +readonly local_version="$(/usr/libexec/PlistBuddy -c 'print version' "${local_info_plist}")" |
| 496 | +
|
| 497 | +[[ -n "${local_version}" ]] || abort 'You need to set a workflow version in the configuration sheet.' |
| 498 | +[[ "${download_type}" =~ ^(direct|page|github_release)$ ]] || abort "'download_type' (${download_type}) needs to be one of 'direct', 'page', or 'github_release'." |
| 499 | +[[ "${frequency_check}" =~ ^[0-9]+$ ]] || abort "'frequency_check' (${frequency_check}) needs to be a number." |
| 500 | +
|
| 501 | +# Check for updates |
| 502 | +if [[ $(find "${local_info_plist}" -mtime +"${frequency_check}"d) ]]; then |
| 503 | + if ! url_exists "${remote_info_plist}"; then abort "'remote_info_plist' (${remote_info_plist}) appears to not be reachable."; fi # Remote sanity check |
| 504 | +
|
| 505 | + readonly tmp_file="$(mktemp)" |
| 506 | + curl --silent --location --output "${tmp_file}" "${remote_info_plist}" |
| 507 | + readonly remote_version="$(/usr/libexec/PlistBuddy -c 'print version' "${tmp_file}")" |
| 508 | +
|
| 509 | + if [[ "${local_version}" == "${remote_version}" ]]; then |
| 510 | + touch "${local_info_plist}" # Reset timer by touching local file |
| 511 | + exit 0 |
| 512 | + fi |
| 513 | +
|
| 514 | + if [[ "${download_type}" == 'page' ]]; then |
| 515 | + notification 'Opening download page…' |
| 516 | + open "${workflow_url}" |
| 517 | + exit 0 |
| 518 | + fi |
| 519 | +
|
| 520 | + download_url="$([[ "${download_type}" == 'github_release' ]] && 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}")" |
| 521 | +
|
| 522 | + if url_exists "${download_url}"; then |
| 523 | + notification 'Downloading and installing…' |
| 524 | + curl --silent --location --output "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow" "${download_url}" |
| 525 | + open "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow" |
| 526 | + else |
| 527 | + abort "'workflow_url' (${download_url}) appears to not be reachable." |
| 528 | + fi |
| 529 | +fi</string> |
| 530 | + <key>scriptargtype</key> |
| 531 | + <integer>1</integer> |
| 532 | + <key>scriptfile</key> |
| 533 | + <string></string> |
| 534 | + <key>type</key> |
| 535 | + <integer>0</integer> |
| 536 | + </dict> |
| 537 | + <key>type</key> |
| 538 | + <string>alfred.workflow.action.script</string> |
| 539 | + <key>uid</key> |
| 540 | + <string>7AEEE496-6258-4811-A26B-16F2133EA5C7</string> |
| 541 | + <key>version</key> |
| 542 | + <integer>2</integer> |
| 543 | + </dict> |
443 | 544 | </array>
|
444 | 545 | <key>readme</key>
|
445 | 546 | <string># Image Shrinker
|
@@ -503,6 +604,17 @@ The workflow accepts one image file
|
503 | 604 | <key>ypos</key>
|
504 | 605 | <real>195</real>
|
505 | 606 | </dict>
|
| 607 | + <key>7AEEE496-6258-4811-A26B-16F2133EA5C7</key> |
| 608 | + <dict> |
| 609 | + <key>colorindex</key> |
| 610 | + <integer>12</integer> |
| 611 | + <key>note</key> |
| 612 | + <string>OneUpdater</string> |
| 613 | + <key>xpos</key> |
| 614 | + <real>1455</real> |
| 615 | + <key>ypos</key> |
| 616 | + <real>455</real> |
| 617 | + </dict> |
506 | 618 | <key>8E04C74A-AFA3-45A5-AB78-FBD21C7699C8</key>
|
507 | 619 | <dict>
|
508 | 620 | <key>xpos</key>
|
|
0 commit comments