diff --git a/README.md b/README.md index d992169..9cbbfb3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ Uploads files to various services via universal action. Displays results/status via notifications, filter keyword and even past results via a log file. -[**Download latest release**](https://github.com/deafmute1/alfred-upload/raw/main/Upload%20Files.alfredworkflow) - - ### Currently supported upload backends **Nextcloud Share**: @@ -11,18 +8,15 @@ Displays results/status via notifications, filter keyword and even past results - Copies selected files or folders to a given directory inside the desktop sync target - must set ncdest variable for this - Generates a share link once file is uploaded and sends it to clipboard. - **Immich**: - Uploads images - Requires API key and server URL variables to be set +**ptpimg.me** ### Additional tools -- uploadres (keyword): displays status of last run upload for each backend +- upload: displays status of last run upload for backend, defaults to all. Running this keyword also triggers autoupdate mechanism. -### Changelog -v1.2 (2024-05-24) -- Added dialogue pop-up on first run to remove com.apple.quarantine from scripts/binaries --- diff --git a/Upload Files.alfredworkflow b/Upload Files.alfredworkflow index f4a568f..35923ed 100644 Binary files a/Upload Files.alfredworkflow and b/Upload Files.alfredworkflow differ diff --git a/workflow/info.plist b/workflow/info.plist index aba086c..348e222 100644 --- a/workflow/info.plist +++ b/workflow/info.plist @@ -27,23 +27,23 @@ destinationuid - 76514825-C917-4FB9-8B0A-FA66AAAF0C54 + 0E46661F-558F-4479-A3F8-26E735BA8DFB modifiers 0 modifiersubtext + sourceoutputuid + EBFDB96E-37C5-4C62-8526-FC76B6A43F37 vitoclose destinationuid - 0E46661F-558F-4479-A3F8-26E735BA8DFB + 76514825-C917-4FB9-8B0A-FA66AAAF0C54 modifiers 0 modifiersubtext - sourceoutputuid - EBFDB96E-37C5-4C62-8526-FC76B6A43F37 vitoclose @@ -61,7 +61,7 @@ - 39DF0D33-378C-484C-A931-11785625DD43 + 4E2D6183-4E1D-4BFF-9228-CE4B25DCF736 destinationuid @@ -74,11 +74,11 @@ - 4E2D6183-4E1D-4BFF-9228-CE4B25DCF736 + 76514825-C917-4FB9-8B0A-FA66AAAF0C54 destinationuid - 39DF0D33-378C-484C-A931-11785625DD43 + 2AF36373-AFB0-4DF0-8CD7-58EBD960FF5B modifiers 0 modifiersubtext @@ -87,11 +87,36 @@ - 76514825-C917-4FB9-8B0A-FA66AAAF0C54 + 80D88C38-97E4-487F-8748-BCFB65FBF417 destinationuid - 2AF36373-AFB0-4DF0-8CD7-58EBD960FF5B + 0E46661F-558F-4479-A3F8-26E735BA8DFB + modifiers + 0 + modifiersubtext + + sourceoutputuid + DD0438C3-B477-4607-BDD2-AE2834223371 + vitoclose + + + + destinationuid + CF38F6CC-6BFD-4D93-ACA7-8DCC6603FCC9 + modifiers + 0 + modifiersubtext + + vitoclose + + + + 83BEC7A8-251F-4F7A-84F5-22FB42572BF6 + + + destinationuid + 98372A01-9B03-45A6-8CB6-4FA3F69FBE24 modifiers 0 modifiersubtext @@ -113,6 +138,19 @@ + 98372A01-9B03-45A6-8CB6-4FA3F69FBE24 + + + destinationuid + DD0D9E7E-D3E6-4589-AABD-F25B95F85E7B + modifiers + 0 + modifiersubtext + + vitoclose + + + AA137055-BEC3-4065-AF5E-2D6B79AEBBF4 @@ -163,20 +201,21 @@ - CFF09A71-1018-452C-800C-D4EC54DB016C + CF38F6CC-6BFD-4D93-ACA7-8DCC6603FCC9 destinationuid - 39DF0D33-378C-484C-A931-11785625DD43 + 2AF36373-AFB0-4DF0-8CD7-58EBD960FF5B modifiers 0 modifiersubtext - sourceoutputuid - fileexists vitoclose + + CFF09A71-1018-452C-800C-D4EC54DB016C + destinationuid 0CCCBD58-19A7-43AE-B29F-23223A26039A @@ -187,6 +226,18 @@ vitoclose + + destinationuid + D9349DDE-D6CD-4C92-AB16-210E8166B39B + modifiers + 0 + modifiersubtext + + sourceoutputuid + fileexists + vitoclose + + D9349DDE-D6CD-4C92-AB16-210E8166B39B @@ -214,6 +265,18 @@ vitoclose + + destinationuid + 80D88C38-97E4-487F-8748-BCFB65FBF417 + modifiers + 0 + modifiersubtext + + sourceoutputuid + 0FA93DC9-11E5-43F6-A11A-ACFDEC4A7946 + vitoclose + + DD0D9E7E-D3E6-4589-AABD-F25B95F85E7B @@ -277,11 +340,11 @@ argumenttrimmode 0 argumenttype - 2 + 1 escaping 102 keyword - uploadres + upload queuedelaycustom 3 queuedelayimmediatelyinitially @@ -293,7 +356,13 @@ runningsubtext Please wait... script - python3 ./upstat.py --xml immich nextcloud + if [[ "$1" == "update" ]]; then + python ./upload.py --update +elif [[ -n "$1" ]]; then + python3 ./upload.py --xml "$1" +else + python3 ./upload.py --xml +fi scriptargtype 1 scriptfile @@ -305,7 +374,7 @@ type 11 withspace - + type alfred.workflow.input.scriptfilter @@ -314,6 +383,27 @@ version 3 + + config + + lastpathcomponent + + onlyshowifquerypopulated + + removeextension + + text + Required variables for {var:backend} not set. + title + Error + + type + alfred.workflow.output.notification + uid + 0E46661F-558F-4479-A3F8-26E735BA8DFB + version + 1 + config @@ -322,7 +412,8 @@ escaping 102 script - ./share-nc.sh --dest "$ncdest" --nec ./nec --direct --stable "$1" | tee -a "${alfred_workflow_data}/nextcloud.log" | tail -n 2 | head -n 1 + touch "${alfred_workflow_data}/has-run" +xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec scriptargtype 1 scriptfile @@ -333,7 +424,7 @@ type alfred.workflow.action.script uid - 76514825-C917-4FB9-8B0A-FA66AAAF0C54 + 4E2D6183-4E1D-4BFF-9228-CE4B25DCF736 version 2 @@ -354,6 +445,27 @@ version 1 + + config + + button1 + Allow + button2 + Cancel + button3 + + description + This workflow relies on internal scripts and binaries that you must allow to run. Selecting allow will remove the xattr com.apple.quarantine from files shiped with the workflow. + title + Initalise workflow by alllowing binaries to run + + type + alfred.workflow.utility.dialog + uid + 0CCCBD58-19A7-43AE-B29F-23223A26039A + version + 1 + config @@ -411,36 +523,77 @@ config - lastpathcomponent - - onlyshowifquerypopulated - - removeextension + concurrently - text - {query} - title - Result of {var:backend} upload + escaping + 102 + script + out=$(./share-nc.sh --dest "$ncdest" --nec ./nec --direct --stable "$file") +printf "\n%s" "$out" >> "${alfred_workflow_data}/nextcloud.log" +printf "%s" "$out" | awk -F ';' 'NR==2 {print $1}' + +if [[ "$out" -eq 0 ]]; then + echo "Success" +else + echo "Failure" +fi + scriptargtype + 1 + scriptfile + + type + 11 type - alfred.workflow.output.notification + alfred.workflow.action.script uid - 2AF36373-AFB0-4DF0-8CD7-58EBD960FF5B + 76514825-C917-4FB9-8B0A-FA66AAAF0C54 version - 1 + 2 config - fileutivariablename - - outputfileuti + conditions + + + inputstring + {var:immichkey} + matchcasesensitive + + matchmode + 0 + matchstring + + outputlabel + No url + uid + DD0438C3-B477-4607-BDD2-AE2834223371 + + + inputstring + {var:immichurl} + matchcasesensitive + + matchmode + 0 + matchstring + + outputlabel + No key + uid + 6E9E6D7D-1DAE-44A8-9AD4-745347ABA28D + + + elselabel + good + hideelse type - alfred.workflow.utility.file + alfred.workflow.utility.conditional uid - CFF09A71-1018-452C-800C-D4EC54DB016C + AA137055-BEC3-4065-AF5E-2D6B79AEBBF4 version 1 @@ -477,6 +630,20 @@ uid 59395524-F3A4-4063-A93F-BFA33CF4C366 + + inputstring + {var:backend} + matchcasesensitive + + matchmode + 0 + matchstring + ptpimg + outputlabel + ptpimg + uid + 0FA93DC9-11E5-43F6-A11A-ACFDEC4A7946 + elselabel else @@ -490,6 +657,25 @@ version 1 + + config + + acceptsmulti + 0 + filetypes + + +public.image + + name + Upload to immich + + type + alfred.workflow.trigger.action + uid + 90B8229C-1951-491E-86E3-6A3E854F8445 + version + 1 + config @@ -500,31 +686,29 @@ removeextension text - Required variables for {var:backend} not set. + File: {var:file} title - Error + {var:backend} upload: {query} type alfred.workflow.output.notification uid - 0E46661F-558F-4479-A3F8-26E735BA8DFB + 2AF36373-AFB0-4DF0-8CD7-58EBD960FF5B version 1 config - argument - {const:alfred_workflow_data}/has-run - passthroughargument + fileutivariablename + + outputfileuti - variables - type - alfred.workflow.utility.argument + alfred.workflow.utility.file uid - DD0D9E7E-D3E6-4589-AABD-F25B95F85E7B + CFF09A71-1018-452C-800C-D4EC54DB016C version 1 @@ -532,35 +716,21 @@ config argument - {var:file} + passthroughargument variables - + + backend + immich + file + {query} + type alfred.workflow.utility.argument uid - 39DF0D33-378C-484C-A931-11785625DD43 - version - 1 - - - config - - acceptsmulti - 0 - filetypes - - +public.image - - name - Upload to immich - - type - alfred.workflow.trigger.action - uid - 90B8229C-1951-491E-86E3-6A3E854F8445 + 2C686EE8-7869-49B9-83B9-7BB339052083 version 1 @@ -568,21 +738,19 @@ config argument - + {const:alfred_workflow_data}/has-run passthroughargument variables - backend - immich - file - {query} + status + type alfred.workflow.utility.argument uid - 2C686EE8-7869-49B9-83B9-7BB339052083 + DD0D9E7E-D3E6-4589-AABD-F25B95F85E7B version 1 @@ -594,8 +762,18 @@ escaping 102 script - touch "${alfred_workflow_data}/has-run" -xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec + logto="${alfred_workflow_data}/immich.log" +printf "\n%s" "$file" >> "$logto" + +out=$(./immich-go -no-colors-log -server "$immichurl" -key "$immichkey" upload "$file" | awk '/errors/ {printf $1}') + +printf "\n%s;" "$out" >> "$logto" + +if [[ "$out" -eq 0 ]]; then + echo "Success" +else + echo "Failure" +fi scriptargtype 1 scriptfile @@ -606,7 +784,7 @@ xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec type alfred.workflow.action.script uid - 4E2D6183-4E1D-4BFF-9228-CE4B25DCF736 + F8190FCC-73F9-46F8-840D-CB228AEE4E10 version 2 @@ -617,21 +795,7 @@ xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec inputstring - {var:immichkey} - matchcasesensitive - - matchmode - 0 - matchstring - - outputlabel - No url - uid - DD0438C3-B477-4607-BDD2-AE2834223371 - - - inputstring - {var:immichurl} + {var:ptpimgkey} matchcasesensitive matchmode @@ -641,7 +805,7 @@ xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec outputlabel No key uid - 6E9E6D7D-1DAE-44A8-9AD4-745347ABA28D + DD0438C3-B477-4607-BDD2-AE2834223371 elselabel @@ -652,28 +816,48 @@ xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec type alfred.workflow.utility.conditional uid - AA137055-BEC3-4065-AF5E-2D6B79AEBBF4 + 80D88C38-97E4-487F-8748-BCFB65FBF417 version 1 config - button1 - Allow - button2 - Cancel - button3 + acceptsmulti + 0 + filetypes + + +public.image + + name + Upload to ptpimg.me + + type + alfred.workflow.trigger.action + uid + 83BEC7A8-251F-4F7A-84F5-22FB42572BF6 + version + 1 + + + config + + argument - description - This workflow relies on internal scripts and binaries that you must allow to run. Selecting allow will remove the xattr com.apple.quarantine from files shiped with the workflow. - title - Initalise workflow by alllowing binaries to run + passthroughargument + + variables + + backend + ptpimg + file + {query} + type - alfred.workflow.utility.dialog + alfred.workflow.utility.argument uid - 0CCCBD58-19A7-43AE-B29F-23223A26039A + 98372A01-9B03-45A6-8CB6-4FA3F69FBE24 version 1 @@ -685,15 +869,20 @@ xattr -d com.apple.quarantine ./immich-go ./share-nc.sh ./nec escaping 102 script - logto="${alfred_workflow_data}/immich.log" -exec > >(tee -a "$logto") -mkdir -p "${alfred_workflow_data}" -printf "Uploaded "$1" with " -./immich-go -no-colors-log -server "$immichurl" -key "$immichkey" upload "$1" | awk '/errors/{printf $1" "$2}' -printf " at $(date +"%Y-%m-%d %H:%M")" -printf " -NULL -" >> "$logto" + out=$(curl -F "file-upload[0]=@${file}" -F api_key="$ptpimgkey" "https://ptpimg.me/upload.php") +slug=$(printf "%s" "$out" | awk '/code/ {print $2}' | tr -d "\",") +ext=$(printf "%s" "$out" | awk '/ext/ {print $2}' | tr -d "\",") +url="https://ptpimg.me/${slug}.${ext}" +logto="${alfred_workflow_data}/ptpimg.log" + +if [ ${#slug} -eq 6 ]; then + pbcopy <<< "$url" + printf "\n%s\n0;%s" "$file" "$url" >> "$logto" + printf "Success" +else + printf "\n%s\n1;" "$file" >> "$logto" + print "Failure" +fi scriptargtype 1 scriptfile @@ -704,7 +893,7 @@ NULL type alfred.workflow.action.script uid - F8190FCC-73F9-46F8-840D-CB228AEE4E10 + CF38F6CC-6BFD-4D93-ACA7-8DCC6603FCC9 version 2 @@ -720,14 +909,15 @@ Displays results/status via notifications, filter keyword and even past results - Copies selected files or folders to a given directory inside the desktop sync target - must set ncdest variable for this - Generates a share link once file is uploaded and sends it to clipboard. - **Immich**: - Uploads images - Requires API key and server URL variables to be set +**ptpimg.me** ### Additional tools -- uploadres (keyword): displays status of last run upload for each backend +- upload: displays status of last run upload for backend, defaults to all. Running this keyword also triggers autoupdate mechanism. + --- @@ -737,121 +927,142 @@ Cloud icon (icon.png) created by graphicmall - Flaticon (https://www.flaticon.co 0CCCBD58-19A7-43AE-B29F-23223A26039A xpos - 450 + 380 ypos - 455 + 305 0D512524-37A5-4908-A842-73A88AF7C919 xpos - 55 - ypos 40 + ypos + 170 0E46661F-558F-4479-A3F8-26E735BA8DFB xpos - 990 + 825 ypos - 350 + 225 1EC0359C-48ED-4D32-B2F3-F2E593224F01 xpos - 850 + 700 ypos - 240 + 325 2AF36373-AFB0-4DF0-8CD7-58EBD960FF5B xpos - 1400 + 1055 ypos - 315 + 410 2C686EE8-7869-49B9-83B9-7BB339052083 xpos - 220 + 165 ypos - 425 + 430 - 39DF0D33-378C-484C-A931-11785625DD43 + 4E2D6183-4E1D-4BFF-9228-CE4B25DCF736 xpos - 665 + 455 ypos - 355 + 270 - 4E2D6183-4E1D-4BFF-9228-CE4B25DCF736 + 76514825-C917-4FB9-8B0A-FA66AAAF0C54 xpos - 530 + 825 ypos - 430 + 335 - 76514825-C917-4FB9-8B0A-FA66AAAF0C54 + 80D88C38-97E4-487F-8748-BCFB65FBF417 xpos - 1140 + 700 ypos - 220 + 485 + + 83BEC7A8-251F-4F7A-84F5-22FB42572BF6 + + xpos + 45 + ypos + 505 90B8229C-1951-491E-86E3-6A3E854F8445 xpos - 50 + 45 ypos 400 + 98372A01-9B03-45A6-8CB6-4FA3F69FBE24 + + xpos + 165 + ypos + 535 + AA137055-BEC3-4065-AF5E-2D6B79AEBBF4 xpos - 845 + 700 ypos - 440 + 390 B067A6DC-E67C-4FBB-AC5E-A1774A154167 xpos - 55 + 45 ypos - 230 + 295 - CFF09A71-1018-452C-800C-D4EC54DB016C + CF38F6CC-6BFD-4D93-ACA7-8DCC6603FCC9 xpos - 385 + 825 ypos + 545 + + CFF09A71-1018-452C-800C-D4EC54DB016C + + xpos 340 + ypos + 420 D9349DDE-D6CD-4C92-AB16-210E8166B39B xpos - 750 + 590 ypos - 345 + 390 DD0D9E7E-D3E6-4589-AABD-F25B95F85E7B xpos - 305 + 290 ypos - 350 + 430 E986CBE7-F9DA-4C82-8917-5CDD32FC9C37 xpos - 210 + 165 ypos - 265 + 325 F8190FCC-73F9-46F8-840D-CB228AEE4E10 xpos - 1130 + 825 ypos - 465 + 440 userconfigurationconfig @@ -919,11 +1130,30 @@ Cloud icon (icon.png) created by graphicmall - Flaticon (https://www.flaticon.co variable immichurl + + config + + default + + placeholder + + required + + trim + + + description + Required for ptpimg.me. To get this key, log in to ptpimg.me, open the dev tools console and type: document.getElementById('api_key').value + label + ptpimg.me API key + type + textfield + variable + ptpimgkey + - variablesdontexport - version - 1.2 + 1.3 webaddress def.au diff --git a/workflow/prefs.plist b/workflow/prefs.plist index 3f20288..c00578e 100644 --- a/workflow/prefs.plist +++ b/workflow/prefs.plist @@ -8,5 +8,7 @@ https://immich.def.au ncdest ~/Nextcloud/share + ptpimgkey + 6f4cc8e5-7faf-42cb-ae7a-bd4e25b2b4ab diff --git a/workflow/share-nc.sh b/workflow/share-nc.sh index 2f14218..d416e1b 100755 --- a/workflow/share-nc.sh +++ b/workflow/share-nc.sh @@ -25,50 +25,50 @@ if [ -z "$srcPath" ]; then exit 1 fi -if [ -d "$srcPath" ]; then - # always use indirect links for folder upload. - direct=false -fi +# disable direct for directories +[ -d "$srcPath" ] && direct=false -# add slug to dest filename if necessary to avoid collisions. -cnt=1 -propfileName="$fileName" -while [ -e "${ncRoot}/${propfileName}" ]; do - propfileName="${fileName%%.*}-${cnt}.${fileName#*.}" - (( cnt+=1 )) -done -fileName="$propfileName" +case "$srcPath" in + "$ncRoot"*) + [ "$stable" != true ] && echo "File in ${ncRoot} already; not copying" ;; + *) + # add slug to dest filename if necessary to avoid collisions. + cnt=1 + propfileName="$fileName" + while [ -e "${ncRoot}/${propfileName}" ]; do + propfileName="${fileName%%.*}-${cnt}.${fileName#*.}" + (( cnt+=1 )) + done + fileName="$propfileName" -cp -r "$srcPath" "${ncRoot}/${fileName}" + cp -r "$srcPath" "${ncRoot}/${fileName}" + ;; +esac -# retry based on vars while waiting for nextcloud to sync -out=$("$necPath" share --expire 'in 6 weeks' "${ncRoot}/${fileName}" 2>&1) cnt=0 -while [ "$out" == "$ERR_STRING" ] && [ $cnt -lt "$RETRY" ]; do - if [ "$stable" != true ]; then - echo "File not synced to cloud; retrying" - fi - sleep "$RETRY_TIME" +out=$("$necPath" ls | awk '/config.yaml/ {print $3}' | head -n 1) +if [ -n "$out" ]; then + # retry based on vars while waiting for nextcloud to sync out=$("$necPath" share --expire 'in 6 weeks' "${ncRoot}/${fileName}" 2>&1) - (( cnt+=1 )) -done + while [ "$out" == "$ERR_STRING" ] && [ $cnt -lt "$RETRY" ]; do + [ "$stable" != true ] && echo "File not synced to cloud; retrying" + sleep "$RETRY_TIME" + out=$("$necPath" share --expire 'in 6 weeks' "${ncRoot}/${fileName}" 2>&1) + (( cnt+=1 )) + done +fi # Stable output format for last 2 lines of stdout: # \n -at=$(date +"%Y-%m-%d %H:%M") if [ "$out" == "$ERR_STRING" ]; then - printf "Failure to upload %s after %s retries at %s" "$srcPath" "$cnt" "$at" - printf " - " + printf "%s" "$cnt" exit 1 else out=$(tail -n 1 <<< "$out") if [ "$direct" = true ]; then out="${out}/download/${fileName}" fi - printf "Success uploading %s at %s" "$srcPath" "$at" - printf " - %s" "$out" + printf "%s\n0;%s" "$srcPath" "$out" pbcopy <<< "$out" exit 0 fi diff --git a/workflow/upload.py b/workflow/upload.py new file mode 100644 index 0000000..14414fd --- /dev/null +++ b/workflow/upload.py @@ -0,0 +1,74 @@ +import os +from workflow import Workflow +import sys, subprocess +from argparse import ArgumentParser + +backends = ["immich", "nextcloud", "ptpimg"] +pretty_names = { + "immich" : "Immich", + "nextcloud": "Nextcloud", + "ptpimg": "ptpimg.me" +} +icons = { + "immich" : "./90B8229C-1951-491E-86E3-6A3E854F8445.png", + "nextcloud": "./B067A6DC-E67C-4FBB-AC5E-A1774A154167.png", + "ptpimg": "./icon.png" +} +def parse_args(): + parser = ArgumentParser() + # notify.notify is currently broken; use builtin alfred notification service instead + #parser.add_argument('--notify', nargs='*', choices=backends.append("all"), default=None) + parser.add_argument('--xml', nargs='*', choices=backends) + #parser.add_argument('--info', default=None) + r=parser.parse_args() + if r.xml == []: + r.xml = backends + return r + +def main(wf): + args = parse_args() + + # Standard logging for backends is that the last two lines are as folllows: + # \n <0 if success else 1>; + def get_info(b): + try: + res = subprocess.run( + ['tail', '-n', '2', wf.datafile(f'{b}.log')], capture_output=True + ).stdout.decode().split('\n') + res = res[:1] + res[1].split(';') + r = { + "url": res[2] if res[2].startswith('http') else 'None', + "filename": os.path.basename(res[0]), + "status": "Success" if int(res[1]) == 0 else "Failure", + "copytext": '' + } + if r['status'] == "Success" and r['url'] is not None: + r['copytext'] = "; ⌘C to copy URL" + return r + except: + return { + "url": 'None', + "filename": 'None', + "status": "Failed to retrieve status data", + "copytext": '' + } + info={ b: get_info(b) for b in backends} + + # if args.notify is not None: + # for b in args.notify: + # notify.notify(title=f"{b} upload", message=info[b][0]) + if args.xml is not None: + for backend in args.xml: + info_b = info[backend] + wf.add_item( + title=pretty_names[backend] + ': ' + info_b['status'], + icon=icons[backend], + subtitle='File: ' + info_b['filename'] + info_b['copytext'], + copytext=info_b['url'], + valid=True if info_b['copytext'] != '' else False + ) + wf.send_feedback() + +if __name__ == '__main__': + wf = Workflow(libraries=['./libs'], update_settings={'github_slug': 'deafmute1/alfred-upload'}) + sys.exit(wf.run(main)) \ No newline at end of file diff --git a/workflow/upstat.py b/workflow/upstat.py deleted file mode 100644 index 55f10fa..0000000 --- a/workflow/upstat.py +++ /dev/null @@ -1,55 +0,0 @@ -from workflow import Workflow, notify -import sys, subprocess -from argparse import ArgumentParser - -backends = ["immich", "nextcloud"] - -def parse_args(): - parser = ArgumentParser() - # notify.notify is currently broken; use builtin alfred notification service instead - #parser.add_argument('--notify', nargs='*', choices=backends.append("all"), default=None) - parser.add_argument('--xml', nargs='*', choices=backends, default=backends) - parser.add_argument('--info', default=None) - r=parser.parse_args() - return r - -def main(wf): - args = parse_args() - # Standard logging for backends is that the last two lines are as folllows: - # \n - def get_info(b): - if args.info is not None: - return [args.info, "NULL"] - try: - return subprocess.run( - ['tail', '-n', '2', wf.datafile(f'{b}.log')], capture_output=True - ).stdout.decode().split('\n') - except: - return ["Failed to read data for {b}", " "] - info={ b: get_info(b) for b in backends} - - # if args.notify is not None: - # for b in args.notify: - # notify.notify(title=f"{b} upload", message=info[b][0]) - if args.xml is not None: - xml = { - "nextcloud": { - "title": info['nextcloud'][0], - "icon": "./B067A6DC-E67C-4FBB-AC5E-A1774A154167.png", - "subtitle": "Status of last nc upload via alfred; ⌘C to copy URL if available", - "copytext": info['nextcloud'][1] if info['nextcloud'][1].startswith("http") else None - }, - "immich": { - "title": info['immich'][0], - "icon": "./90B8229C-1951-491E-86E3-6A3E854F8445.png", - "subtitle": "status of last immich upload via alfred", - "valid":False - }, - } - for b in args.xml: - wf.add_item(**xml[b]) - wf.send_feedback() - -if __name__ == '__main__': - wf = Workflow() - sys.exit(wf.run(main)) \ No newline at end of file diff --git a/workflow/workflow/notify.py b/workflow/workflow/notify.py index f119cf7..5ed302a 100644 --- a/workflow/workflow/notify.py +++ b/workflow/workflow/notify.py @@ -333,7 +333,7 @@ def png_to_icns(png_path, icns_path): '--convert', 'icns', '--output', icns_path, iconset] - print(f'cmd {cmd}') + retcode = subprocess.call(cmd) if retcode != 0: raise RuntimeError(f'iconset exited with {retcode}')