Created
May 27, 2015 11:47
-
-
Save dirkjanfaber/fd5bb7447593bda3d977 to your computer and use it in GitHub Desktop.
Script for updating the save folder of a Scansnap manager preference. This ought to be run from cron.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script takes care of changing the Scansnap Manager | |
# save folder every month. This script ought to be run from | |
# cron. | |
# | |
# Dirk-Jan Faber | |
ROOTSAVE=~/Documents/scan | |
SAVEDIR="${ROOTSAVE}/$(date +'%Y/%m')" | |
PLIST=~/Library/Preferences/jp.co.pfu.ScanSnap.V10L10.plist | |
# Name is first argument, fall back to "Batch scan" | |
NAME=${1:-Batch scan} | |
# Search for the preferences entry that matches $NAME; we need to count the entries | |
# in order to change the correct one. | |
CNT=$(/usr/libexec/PlistBuddy -c "print 'Scanning Settings:'" ${PLIST} |\ | |
awk -F' = ' -v name="${NAME}" ' | |
BEGIN { c=0; found=0 }; | |
/Setting Name/ { if ( $2 == name ) { found=1; exit }; c++; }; | |
END { if ( found == 1 ) { print c } else { print "" }; }; ') | |
# Exit if we did not find a match on ${NAME} | |
[ -z ${CNT} ] && ( echo "No match on [${NAME}] found in ${PLIST}" ; exit 1 ) | |
# Create the save folder if it does not exist yet | |
[ ! -d ${SAVEDIR} ] && mkdir -p ${SAVEDIR} | |
# Update the Save folder | |
/usr/libexec/PlistBuddy -c "set 'Scanning Settings:'${CNT}':Save Folder' ${SAVEDIR}" ${PLIST} | |
# Prevent OSX's cache to use the cached settings (and update the plist after us) | |
defaults read ${PLIST} > /dev/null | |
# Print the current setting | |
/usr/libexec/PlistBuddy -c 'print "Scanning Settings:'${CNT}':Save Folder"' ${PLIST} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment