Skip to content

Commit

Permalink
version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannicoppola committed Sep 30, 2022
1 parent de70315 commit 688475c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ src="https://img.shields.io/github/downloads/giovannicoppola/alfred-almanac/tota
<a name="acknowledgments"></a>
# Acknowledgments
- [Igor Chubin](https://twitter.com/igor_chubin) for developing the amazing `wttr.in`
- [@vitorgalvao](https://github.com/vitorgalvao) for suggestions and great additions
- The [Alfred forum](https://www.alfredforum.com) community.

<a name="changelog"></a>
# Changelog

- 09-29-2022: version 1.3 added autoupdate, quicklookurl preview, keyword configurable (thanks @vitorgalvao!)
- 08-07-2022: version 1.2 merging @vitorgalvao's changes to update Workflow Environment Variables to User Configuration
- 03-30-2022: version 1.1 (switched to `requests` package for web request handling)
- 03-22-2022: version 1.0
Expand Down
Binary file added releases/alfred almanacv1-3.alfredworkflow
Binary file not shown.
126 changes: 123 additions & 3 deletions source/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<dict>
<key>bundleid</key>
<string>giovanni-almanac</string>
<key>category</key>
<string>Productivity</string>
<key>category</key>
<string>Productivity</string>
<key>connections</key>
<dict>
<key>3B9C56F6-92CA-4E97-92EF-20C22F571619</key>
Expand Down Expand Up @@ -40,6 +40,16 @@
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>72A6C50C-1A20-4C3F-892E-C91FA5BB13BA</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>9FAAF43A-64B2-4222-9BC4-476F44DB774E</key>
<array>
Expand Down Expand Up @@ -274,6 +284,103 @@ python3 almanac.py $1 "${LOCATION}"</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>0</integer>
<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/giovannicoppola/alfred-almanac/main/source/info.plist'
readonly workflow_url='https://github.com/giovannicoppola/alfred-almanac'
readonly download_type='github_release'
readonly frequency_check='30'
# 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 f -name 'notificator')"
if [[ -f "${notificator}" &amp;&amp; "$(/usr/bin/file --brief --mime-type "${notificator}")" == 'text/x-shellscript' ]]; then
"${notificator}" --message "${1}" --title "${alfred_workflow_name}" --subtitle 'A new version is available'
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
# Remote sanity check
if ! url_exists "${remote_info_plist}"; then
abort "'remote_info_plist' (${remote_info_plist}) appears to not be reachable."
fi
readonly tmp_file="$(mktemp)"
curl --silent --location --output "${tmp_file}" "${remote_info_plist}"
readonly remote_version="$(/usr/libexec/PlistBuddy -c 'print version' "${tmp_file}")"
rm "${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
readonly download_url="$(
if [[ "${download_type}" == 'github_release' ]]; then
osascript -l JavaScript -e 'function run(argv) { return JSON.parse(argv[0])["assets"].find(asset =&gt; asset["browser_download_url"].endsWith(".alfredworkflow"))["browser_download_url"] }' "$(curl --silent "https://api.github.com/repos/${workflow_url}/releases/latest")"
else
echo "${workflow_url}"
fi
)"
if url_exists "${download_url}"; then
notification 'Downloading and installing…'
readonly download_name="$(basename "${download_url}")"
curl --silent --location --output "${HOME}/Downloads/${download_name}" "${download_url}"
open "${HOME}/Downloads/${download_name}"
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>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>72A6C50C-1A20-4C3F-892E-C91FA5BB13BA</string>
<key>version</key>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
<string>- Launch `alfred-almanac` to retrieve weather and other almanac information from default locations ...
Expand Down Expand Up @@ -326,6 +433,17 @@ python3 almanac.py $1 "${LOCATION}"</string>
<key>ypos</key>
<real>305</real>
</dict>
<key>72A6C50C-1A20-4C3F-892E-C91FA5BB13BA</key>
<dict>
<key>colorindex</key>
<integer>12</integer>
<key>note</key>
<string>OneUpdater</string>
<key>xpos</key>
<real>305</real>
<key>ypos</key>
<real>615</real>
</dict>
<key>9FAAF43A-64B2-4222-9BC4-476F44DB774E</key>
<dict>
<key>xpos</key>
Expand Down Expand Up @@ -435,8 +553,10 @@ python3 almanac.py $1 "${LOCATION}"</string>
<string>SPECIAL_DAY</string>
</dict>
</array>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.2</string>
<string>1.3</string>
<key>webaddress</key>
<string>https://github.com/giovannicoppola/alfred-almanac</string>
</dict>
Expand Down

0 comments on commit 688475c

Please sign in to comment.