Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
luckman212 committed Feb 27, 2023
1 parent 74342ae commit 872dffc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions alfred_validate_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ function open_orphan_dir() {

case $1 in
-o|--open) #open dirs
open -a Finder "$HOME/$db_path/$db_name.data"
open -a Finder "$db_path/$db_name.data"
open_orphan_dir
exit
;;
esac

# populate array with list of image clips from database
clipArray=()
while IFS= read -r line; do clipArray+=("$line"); done < <(/usr/bin/sqlite3 "$HOME/$db_path/$db_name" "SELECT dataHash FROM clipboard WHERE dataType = 1;")
while IFS= read -r line; do clipArray+=("$line"); done < <(/usr/bin/sqlite3 "$db_path/$db_name" "SELECT dataHash FROM clipboard WHERE dataType = 1;")

# loop thru all tiffs in database storage folder, and validate
cd "$HOME/$db_path/$db_name.data" || { echo "could not cd to db storage folder"; exit 1; }
cd "$db_path/$db_name.data" || { echo "could not cd to db storage folder"; exit 1; }

shopt -s nullglob # enable
for i in *.tiff *.png ; do
Expand Down
15 changes: 12 additions & 3 deletions cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
def envvar(v: str, dv: str) -> str:
return str(os.getenv(v) or dv)

#for checkboxes - unchecked aka `0` returns `false`
def envvar_to_bool(v: str) -> str:
return str(bool(os.getenv(v))).lower()
try:
b = int(os.getenv(v))
except:
b = 0
return str(bool(b)).lower()

def envvar_to_int(v: str, dv: int=0) -> int:
try:
Expand All @@ -28,9 +33,9 @@ def envvar_to_int(v: str, dv: int=0) -> int:
#wf vars
db_name = envvar('db_name', 'clipboard.alfdb')
db_path = os.path.expanduser(envvar('db_path', '~/Library/Application Support/Alfred/Databases'))
dest_dir = os.path.expanduser(envvar('dest_dir', '~/Desktop/saved_clips')).lower()
default_format = envvar('default_format', 'png').lower()
delete_after_convert = envvar_to_bool('delete_after_convert')
dest_dir = os.path.expanduser(envvar('dest_dir', '~/Desktop/saved_clips')).lower()
save_to_current = envvar_to_bool('save_to_current')
sf_clip_limit = envvar_to_int('sf_clip_limit', -1)

Expand Down Expand Up @@ -153,7 +158,11 @@ def listitems(fmt='png',num=1):
variables = {
'uidSeed': uidSeed,
'delete_after_convert': delete_after_convert,
'save_to_current': save_to_current
'save_to_current': save_to_current,
'db_name': db_name,
'db_path': db_path,
'dest_dir': dest_dir,
'default_format': default_format
}
output = { "variables": variables, "skipknowledge": True, "items": items }
json.dump(output, sys.stdout)
4 changes: 3 additions & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,10 @@ https://www.alfredforum.com/topic/14400-clipsaver-save-images-from-clipboard-his
<string>db_name</string>
</dict>
</array>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>2.2.0</string>
<string>2.2.1</string>
<key>webaddress</key>
<string>https://github.com/luckman212/alfred_clipsaver_workflow</string>
</dict>
Expand Down
8 changes: 4 additions & 4 deletions save_multi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exit

unset errmsg
num_items=$1
max_clips=$(/usr/bin/sqlite3 "$HOME/$db_path/$db_name" "SELECT COUNT(dataHash) FROM clipboard WHERE dataType = 1;")
max_clips=$(/usr/bin/sqlite3 "$db_path/$db_name" "SELECT COUNT(dataHash) FROM clipboard WHERE dataType = 1;")

re='^[0-9]+$'
if ! [[ $num_items =~ $re ]] ; then
Expand All @@ -37,7 +37,7 @@ if [[ $max_clips -lt "$num_items" ]]; then
fi

# fetch image clips from database
clip_list=$(/usr/bin/sqlite3 "$HOME/$db_path/$db_name" "SELECT dataHash from clipboard WHERE dataType = 1 ORDER BY rowid DESC LIMIT $num_items;")
clip_list=$(/usr/bin/sqlite3 "$db_path/$db_name" "SELECT dataHash from clipboard WHERE dataType = 1 ORDER BY rowid DESC LIMIT $num_items;")

if [[ $save_to_current == "true" ]]; then
if fwin=$(osascript -e 'tell application "Finder" to get POSIX path of (insertion location as alias)' 2>/dev/null); then
Expand All @@ -61,13 +61,13 @@ fmt=${format:-png}
# loop and process
for src_fname in $clip_list; do

tiff_name=$HOME/$db_path/${db_name}.data/$src_fname
tiff_name=$db_path/${db_name}.data/$src_fname
src_basename=${src_fname%.tiff}

if [[ -r $tiff_name ]]; then
if /usr/bin/sips -s format $fmt "$tiff_name" --out "$dest_dir/${src_basename}.$fmt" &>/dev/null; then
if [[ ${delete_after_convert} == true ]]; then
/usr/bin/sqlite3 "$HOME/$db_path/$db_name" "DELETE FROM clipboard WHERE dataHash = \"$src_fname\" AND dataType = 1 LIMIT 1;"
/usr/bin/sqlite3 "$db_path/$db_name" "DELETE FROM clipboard WHERE dataHash = \"$src_fname\" AND dataType = 1 LIMIT 1;"
rm "$tiff_name" &>/dev/null
fi
else
Expand Down
2 changes: 1 addition & 1 deletion save_single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [[ -r $img_pathname ]]; then
fi
if /usr/bin/sips -s format $fmt "$img_pathname" --out "$dest_dir/${img_noext}.$fmt"; then
if [[ ${delete_after_convert} == true ]]; then
/usr/bin/sqlite3 "$HOME/$db_path/$db_name" "DELETE FROM clipboard WHERE dataHash = \"$img_basename\" AND dataType = 1 LIMIT 1;"
/usr/bin/sqlite3 "$db_path/$db_name" "DELETE FROM clipboard WHERE dataHash = \"$img_basename\" AND dataType = 1 LIMIT 1;"
rm "$img_pathname"
fi
open -a Finder "$dest_dir"
Expand Down

0 comments on commit 872dffc

Please sign in to comment.