ãã®æçš¿ã¯äœã«ã€ããŠã§ããïŒ
ãã¿ã³ãã¯ãªãã¯ããã ãã§ã¹ãã£ã³ããããã«Debianã®ãµãŒããŒã§å€ãã¹ãã£ããŒã䜿çšããæ¹æ³ãããã«ã¯èªåãœãŒãã䜿çšããæ¹æ³ã«ã€ããŠããªããããå¿ èŠãªã®ã§ããïŒ
ããã¯ãè·å Žã®çŽããã«æºè¶³ããŠããªããã¹ãŠã®äººã«é©ããŠããŸãã äŸïŒ- çåŸãåŠçãåŠæ ¡ã倧åŠã倧åŠã§èç©ãããè³æã®å±±ã®ãããã¯ã«é¢é£ãã人ã
- åãæžé¡ãæçŽã®éåžžã«å€ãã®å±±ãæã£ãŠãããªãã£ã¹ã¯ãŒã«ãŒ
- æ®éã®äºº-ããããçš®é¡ã®å ¥ã£ãŠããæçŽãè«æ±æžãå°åæãã¹ãã£ã³ããïŒãåç¥ã®ããã«ãå°åæã¯æ¶ããåŸåããããããã¯ãŸãã«ç§ã®åé¡ã§ã-å€æ°ã®å°åæãã¹ãã£ã³ããå¿ èŠããããŸãããããã¯ããŸã䟿å©ã§ã¯ãããŸããïŒ
ãããã©ã®ããã«æ³åã§ããŸããïŒ
ã¯ãããšãŠãç°¡åã§ãã ã¹ãã£ããŒã«çŽãå ¥ãããã¿ã³ãæŒããã¹ãã£ã³ãšåŠçã®çµäºã«é¢ããé³å£°ä¿¡å·ãåŸ ã¡ãå¿ èŠã«å¿ããŠçŽãåãåºããŸãã-GOTO 10ããããŠãç§ã«äœãèµ·ãã£ãã®ã§ããïŒ
äžæããããšãªãæ©èœããã·ã¹ãã ãããã«ããããããã¹ãã£ã³ãšãã©ã«ããŒã«ããèªå䞊ã¹æ¿ãããã°èšé²ããã®ä»ã®ãã©ãã«ãå¯èœã«ãªããŸããã¹ã¯ãªããã«èšè¿°ãããã®ã¯äœã§ãããŸããŸãããã©ãããããã圌ãã¯ç§ã«Epson Perfection 1200Uã¹ãã£ããŒããããŸããã ã·ã³ãã«ãªUSBãã©ã°ã€ã³ã¹ãã£ããŒã¯ããªãå€ãã§ããã解å床ã¯è¯å¥œã§ãã ç§ã¯ãããèªåã®ã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ãããã£ã-ãããŠããã«åŸ ã¡äŒããããã110ãã«ãçšã«èšèšãããŠããã ããŠãåŸã§ãã©ã³ã¹ãå ¥æããŠæ¥ç¶ããŸããã åäœããŸãããWindows XPã§ã®ã¿-Windows 7ã§ã¯ãã©ã€ããŒããªããäºæãããŠããŸããã åäœããŠããWindows 7 x64ã³ã³ãã¥ãŒã¿ãŒã§-ãããŠä»ãæãè ã®ããã«ãäœããã¹ãã£ã³ããå¿ èŠããããã³ã«ä»®æ³ãã·ã³ãèµ·åããŸããããè¿ãã«ä»ã®ã¹ãã£ããŒã¯ãããŸããã§ããã
*æªæã®ããã¡ãŒã«ãŒã«ã€ããŠã®å³ããåŸæã®å Žæ*
æéãçµã€ã«ã€ããŠãäœæ¥ã³ã³ãã¥ãŒã¿ãŒã¯äžæ³šæãªãè¶ã®ãã°ã圌女ã®æ¯èŠªã®è¶³ã®èŠè«ã§å€ãã£ãã Debianã¯ãã銎æã¿ããããããæ°ããã³ã³ãã¥ãŒã¿ãŒã«ã€ã³ã¹ããŒã«ããããšã«ããŸããã ãããŠåã³ãäœããããããŠç·æ¥ã«ã¹ãã£ã³ããå¿ èŠããããšããããŸããã ã¹ãã£ããŒãæ¥ç¶ããŸã-ICMãããã¡ã€ã«ã«å€å°ã®ç·åŒµã¯ãããŸãããåäœããŸãã ã©ãããã誰ãããªãŒãã³ãœãŒã¹ã®ããã«ããããå¯ä»ããããšãã欲æ±ããã£ãããããããèŠã€ããŠã€ã³ã¹ããŒã«ããã ãã§ååã§ãã-ç§ã¯ç解ããŠããŸããã§ãããç§ã¯å¯ãããŸããã æãéèŠãªããšã¯ãäœã§ãæ軜ã«ã¹ãã£ã³ã§ããããã«ãªã£ãããšã§ãã åæ¢ããŸãããGUIã䜿çšããã«ãµãŒããŒã«æ¥ç¶ããŠscanimageãå®è¡ããå Žåã¯ïŒ ããŒããããã¯åäœããŸãã ã¯ã©ã¹ïŒ
ãã®ãããã¹ãã£ããŒæ¬äœã«ã¯ãã¿ã³ããããŸãã 圌女ã¯Windowsã䜿çšããããšãã§ãããææ ããŒãã«ããŸããã ãã ããããã§ãã Googleãžã®ãªã¯ãšã¹ãã§ãscanbuttondãšscanbdã®2ã€ã®ãããžã§ã¯ããèŠã€ãããŸããã æåã®ãã®ã¯å€ããã®ã§ãæåŸã®ã³ãããã¯2006幎ã§ãããããã«ãªããžããªã§èŠã€ãããŸããã åŸã§åºãããšã決ãã2ã€ç®ã¯ãçç±ã¯ç°¡åã§ã-ã³ã³ãã€ã«äžã«ããŸããŸãªçš®é¡ã®åé¡ã絶ããåºãŠããŸããããããããã³ã³ãœãŒã«ã®æ°è¡ã§è§£æ±ºãããŸãããããããã®å€ãããã£ãã®ã§ãç§ã¯åŸç¹ããç ããããšæããŸããã scanbuttondã䜿çšããŸãããé¢é£ããå Žåã¯ããã¹ãŠã®ã¹ã¯ãªãããscanbdã§å®äºããã®ã«åé¡ã§ã¯ãªããšæããŸãã ãã¡ãããåé¡ã¯ã©ããŸã§åé¡ãããã®ãââãšããããšã§ã...ããããä»ã®ãšããã¯scanbuttondã§ãã
scanbuttondã®äœ¿çšãéå§ãã
ãªããžããªããscanbuttondãé 眮ããscanbuttondãå®è¡ãã/ var / log / daemon.logãèŠãŠããã¿ã³ãã¯ãªãã¯ããsleepbuttondããã¿ã³ãæŒãããŠãã解æŸãããããšãåãã§éç¥ããŸãã ãã£ãããïŒ
ããããäœïŒ ãã®åŸããã¹ãŠãç°¡åã§ãã ãŸãã/ etc / default / scanbuttondãç·šéããããŒã¢ã³ãã·ã¹ãã ãšäžç·ã«èµ·åã§ããããã«ããŸãããŸããservice scanbuttond startã³ãã³ãã§èµ·åããŸãã ã©ã®ã¹ã¯ãªãããåŒã³åºãããŸããïŒ
1ã€ç®ã¯initscanner.sh.exampleïŒååãå€æŽããåžæ°ããããããã«ããã®.exampleãåé€ããŸãïŒãã¹ãã£ããŒãæ¥ç¶ããããã³ã«åŒã³åºãããåºæ¬çã«ïŒç§ãç¥ãéãïŒããŸããŸãªæŸèæãæ¥ç¶ããããã®ã€ã³ã¿ãŒãã§ã€ã¹ã§ãããŸããæã«ã¯-éç¥ãšãã®ã³ã°ã
2çªç®ã®ã¹ã¯ãªããã¯ããèå³æ·±ããã®ã§ããã¿ã³ãæŒããããšããã«åŒã³åºãããŸãã ããã¯buttonpressed.sh.exampleãšåŒã°ããååã®æåŸã®éšåããŸãäžèŠã§ãã ãã®ã¹ã¯ãªããã¯ããã¿ã³ãã¯ãªãã¯ããããã³ã«åŒã³åºãããŸãã ãããã®ããŸããŸãªã¹ãã£ã³ã³ãã³ããªã©ããã¹ãŠçªãå¿ èŠãããã®ã¯åœŒã§ãã
ãã¿ã³ã®ã¯ãªãã¯ãåŠçããããã«2ã€ã®ã¹ã¯ãªãããç©ã¿éããŸãã æåã¯BASHã§ãã ãã¿ã³ãæŒããããšãscanbuttondã¯å¶åŸ¡ããã®ã¹ã¯ãªããã«è»¢éãããã¿ã³çªå·ãšã¹ãã£ããŒåã$ 1ããã³$ 2ãšããŠç€ºããŸãã 1ã€ã®ã¹ãã£ããŒãš1ã€ã®ãã¿ã³ããããŸã-åŒæ°ã¯ç¡èŠã§ããŸãïŒãŸã ã¹ãªãŒãç¶æ ã«ãããïŒããåŸã§æãåºããŸããã æåã®ã¹ã¯ãªãã-buttonpressed.sh-ã¯ãå®çŸ©æžã¿ã®ãã©ã¡ãŒã¿ãŒã䜿çšããŠscanimageãåŒã³åºããTIFFã®å®æããç»åãããŒã ãã£ã¬ã¯ããªã®ãã©ã«ããŒã«è»¢éããtiffãjpgã«å€æããŠãã2çªç®ã®ã¹ã¯ãªãããåŒã³åºããŸãã 2çªç®ã®Pythonã¹ã¯ãªããã¯ãå æãããŠããååã«åºã¥ããŠã€ã¡ãŒãžåãéžæããŸãã
æåã®ã¹ã¯ãªããã¯buttonpressed.shã§ã
#!/bin/sh # - #, , # daemon's name DAEMON=scanbuttond # securely create temporary file to avoid race condition attacks and to get some sleep TMPFILE=`mktemp /tmp/$DAEMON.XXXXXX` # lock file LOCKFILE="/tmp/$DAEMON.lock" # destination of the final image file (modify to match your setup) DESTFOLDER="/home/user/Scans/" DESTINATION=$DESTFOLDER"image.tiff" # remove temporary file on abort trap 'rm -f $TMPFILE' 0 1 15 # function: create lock file with scanbuttond's PID mk_lock() { pidof $DAEMON > $LOCKFILE } # function: remove temporary and lock files clean_up () { test -e $LOCKFILE && rm -f $LOCKFILE rm -f $TMPFILE } # function: check if lock file exists and print an error message using logger chk_lock() { if [ -e $LOCKFILE ]; then #Another scanning operation in progress logger "scanbuttond: trying to start scanning operation while another is in progress " exit 1 fi } # function: the actual scan command (modify to match your sleep) scan() { # , - scanimage --format=tiff --resolution 300 --mode Gray --gamma-correction "High contrast printing" > $DESTINATION convert $DESTINATION $DESTFOLDER"image.jpg" logger "Filename: " `python /etc/scanbuttond/convert_scan.py` rm $DESTINATION } chk_lock mk_lock scan clean_up
2çªç®ã®ã¹ã¯ãªããã¯convert_scan.pyã§ã
import os filename = 'image.jpg' directory = "/home/user/Scans" os.chdir(directory) try: filenames = [f for f in os.listdir(directory) if f.endswith('.jpg')] except KeyError: filenames = [] counter = 1 new_filename = 'scan_000.jpg' while new_filename in filenames: new_filename = 'scan_'+str(counter).zfill(3)+'.jpg' counter += 1 print new_filename os.rename(filename, new_filename)
䜿çšããããã«ãæåã®ã¹ã¯ãªããã®DESTFOLDERå€æ°ãš2çªç®ã®ã¹ã¯ãªããã®ãã£ã¬ã¯ããªãå€æŽããŸãã
ãã¹ãŠãå®è¡ãå§ããŸããã æåã®ã¹ã¯ãªãããæåã§èµ·åãããšãæåããŸãã ãããããã¿ã³ã®å Žå-ãªã€ã«ã§ã€ããžã¯ã ç§ã¯ããã«åé¡ãèš±å¯ã«ãããšç ãé ã«èšããŸããã§ãããæããã«ãã¹ã¯ãªããã®åºåã¯ã©ãã«ã衚瀺ãããªãã£ããšããäºå®ã§ãããç§ã¯ãã©ã¢ã°ã©ãŠã³ãã§scanbuttondãå®è¡ããåå5æãŸã§ã«ã®ã¿åºåãèŠããšæããŸãã èŠããã«ãåé¡ã¯ãããŒã¢ã³ã¢ãŒãã§ã¯ããã¹ãŠã®ã¹ã¯ãªããããããŒã¢ã³èªäœã®ããã«ãäžè¬ã«sanedãŠãŒã¶ãŒããå®è¡ããããšããããšã§ãã ã©ã®ãããªæé ãå®è¡ããå¿ èŠããããŸããïŒ
scanbuttondããŠãŒã¶ãŒsanedããèµ·åãããåçãä¿åããããã®ãã©ã«ããŒã/ home / user / Scansã§ããããã©ã«ããŒãžã®ã¢ã¯ã»ã¹ããã¹ãŠã«å ããŠãŠãŒã¶ãŒãŠãŒã¶ãŒã®ããã§ãããšä»®å®ããŸãããã
usermod -aG saned user # user saned chown -R user:saned /home/user/Scans # saned chmod -R 770 /home/user/Scans#
çµè«-ã¹ãã£ããŒã¯ãã¿ã³ã§åäœãããã¹ãŠã®åçãããŒã ãã£ã¬ã¯ããªã«é 眮ããŸããã¹ãã£ã³ã«å¿ èŠãªãã®ãã¹ãã£ã³ããå¿ èŠãããã ãã§ãã¹ãã£ã³ã¯ããŸããã§ããã èŠããã«ããã€ãã®ããã«ãåé¡ã解決ãã代ããã«ãèªå解決ã®æ段ãæžããŸããã ãã€ãã®ããã«ãç§ã¯å¯ããã§ãã
ãããããã£ãšäœãã欲ããïŒ
ããªãã¡ïŒ
ã¹ãã£ã³ããã£ã¬ã¯ããªããšã«èªåçã«ãœãŒãããŸãã ãããã©ã®ããã«æ³åã§ããŸããïŒ
>pybssort list default /home/user/Scans/ >pybssort add math Math >pybssort list default /home/user/Scans/ math /home/user/Scans/Math/ >pybssort set math Default scanning directory is now /home/user/Scans/Math/ >pybssort dir /home/user/scans/Math/ >pybssort add phys Physics Default scanning directory is now /home/user/Scans/Physics/ >pybssort set phys Default scanning directory is now /home/user/Scans/Physics/ >pybssort dir /home/user/Scans/Physics/ >pybssort list default /home/user/Scans/ math /home/user/Scans/Math/ phys /home/user/Scans/Physics/ >pybssort sleep OK, I allow you to sleep... No, wait, finish your article! >pybssort del math OK >pybssort list default /home/user/Scans/ phys /home/user/Scans/Physics/
listãaddãdelãsetã³ãã³ãã䜿çšããŠãã¹ãã£ã³ãã©ã«ããŒãå€æŽããŸãã dirã³ãã³ã-ã¹ã¯ãªããã§çŽæ¥äœ¿çšããããã©ã«ããŒã衚瀺ããŸãã
ãã€ã³ãã¯äœã§ããïŒ
ãã€ã§ããã³ã³ãœãŒã«ã®1ã€ã®ã³ãã³ãã§ã¹ãã£ã³çšã®ãã©ã«ããŒãå€æŽã§ããŸãã ãããŠããã¹ãŠã®ãŠãŒã¶ãŒããããè¡ãããšãã§ããŸã-ãããæãŸãããªãå Žåã¯ãããŒã¿ããŒã¹ã®ãããã©ã«ããŒã®ã¢ã¯ã»ã¹èš±å¯ãå€æŽããã ãã§ãã ã³ã³ããã¹ããäœæããç£èŠããããšãã§ããŸã-ãããŠãã¹ãŠã1ã€ã®ã³ãã³ãã§å®è¡ã§ããŸãã
- æåã«ããããã¯ãåºã«ç©ã¿éããŠè«æãåé¡ããç©çåŠã®ã¡ã¢ãå«ãã¢ãŒã«ã€ããäœæããŸãã
- ã³ã³ãœãŒã«ã§ããpybssort add phys Physicsããšå ¥åããŸãã
- ãªãŒãã¬ããã«ããã眮ãããã¿ã³ãæŒããã¹ãã£ã³ã®çµäºãåŸ ã¡ãã¹ãã£ã³ãããªãŒãã¬ãããæšãŠãŠæ¬¡ã®ãã®ã眮ããŸãã
- ãã¹ãŠã®ã¹ãã£ã³ã¯ããã©ã«ã/ home / user / Scans / Physicsã«ãããŸãã
- æ°åŠã§ã¬ã³ãŒããååŸããpybssortãšå ¥åããŠæ°åŠãšæ°åŠãè¿œå ããããã«ã¹ãã£ã³ããŸãããã®åŸã®ãã¹ãŠã®ã¹ãã£ã³ã¯ã/ home / user / Scans / Mathã§è¡ããŸãã
- ç©çåŠã«é¢ããã¡ã¢ãã¿ã€ãpybssort set physãèšèŒãããå¥ã®çŽãèŠã€ããŸãã-åã³ãã¹ãŠã/ home / user / Scans / Physicsã«é£ã³ãŸãã
ããŒãããããã®ããã©ã«ããphysãmathãäœãšåŒã³ãŸããïŒ ããã§ã代æ°ãã¹ãã®ã¹ãã£ã³ã¯Mathãšãããã©ã«ããŒã§ã®ã¿æå³ããããããã³ã³ããã¹ããšåŒã¶ããšã«ããŸãããå¥åº·ãªç¡ç ã«é¢ããèšäºã¯ãSleepãã©ã«ããŒã®ã³ã³ããã¹ãã§æäŸããã®ãæé©ã§ãã
æåŸã«äœãèµ·ãã£ãã®ã§ããïŒ
ã·ã³ãã«ãªPythonããã°ã©ã ã äžçªäžã®è¡ã¯ããã¹ãŠã®ã³ã³ããã¹ããSQLiteããŒã¿ããŒã¹ã«æ ŒçŽãããããã°ã©ã ãå¿ èŠã«å¿ããŠããããããããååŸãããšããããšã§ãã çŸåšã¢ã¯ãã£ããªã³ã³ããã¹ãã¯ãéåžžããã¬ãŒã³ããã¹ãã®å¥ã®ãã¡ã€ã«ã«ä¿åãããŸããç§ã®æèŠã§ã¯ã1åã®ããŒãã«ãäœæãããããå°ç¡ãã«ããã®ã¯éŠ¬é¹¿ããæãã§ããã ãããã®ã³ã³ããã¹ããæäœããããã®åºæ¬çãªæ©èœã»ããããŒãããäœæ¥ãéå§ããæ©èœïŒããŒãã«ãšãã©ã«ããŒãäœæããïŒã
ããã°ã©ã ãžã®ãªã³ã¯ã¯æ¬¡ã®ãšããã§ãã
gist.github.com/CRImier/7330722
ã€ã³ã¹ããŒã«ã«ã¯äœãå¿ èŠã§ããïŒ
wget https://gist.github.com/CRImier/7330722/raw/pybssort.py # nano pybssort.py chmod +x pybssort.py mv pybssort.py /usr/local/bin/pybssort
ç§ã¯æ³šæããŸã-ããŒã¿ããŒã¹ãããã«ä¿åããããã«/ var / libã«ãã©ã«ããäœæããå¿ èŠããããããåããŠã«ãŒãããå®è¡ããå¿ èŠããããŸãã æåã®èµ·ååŸãã«ãŒãã¯å¿ èŠãããŸããã ã¹ã¯ãªããã®æåã§ãã©ã«ããŒãžã®ãã¹ãç·šéã§ããŸãããã¢ã¯ã»ã¹èš±å¯ã«æ³šæããŠãã ãã-ãã©ã«ããŒã«ã¢ã¯ã»ã¹ã§ããªãããšãã貧ãã人ã ã¯æ¶ãæµããŠæ³£ããŸãã ããªãã¯åœŒãæãããããªãã§ãããïŒ
ãããŠãæ¢åã®ã¹ã¯ãªãããšæ¥ç¶ããæ¹æ³ã¯ïŒ ã¯ããæåã®ã¹ã¯ãªããã§ã¯ãããŒãã³ãŒãã£ã³ã°ãããDESTINATIONã®ä»£ããã«ãpybssort dirããæ¿å ¥ããå¿ èŠãããã2çªç®ã®ã¹ã¯ãªããã§ã¯ãåãå€æ°ãã³ãã³ãã©ã€ã³åŒæ°ã«æž¡ããŸãã
ãã®ãããªãã®ïŒ
æåã®ã¹ã¯ãªãã
... # destination of the final image file (modify to match your setup) DESTFOLDER=`pybssort dir` DESTINATION=$DESTFOLDER"image.tiff" ... # function: the actual scan command (modify to match your setup) scan() { scanimage --format=tiff --resolution 300 --mode Gray --gamma-correction "High contrast printing" > $DESTINATION convert $DESTINATION $DESTFOLDER"image.jpg" logger "Filename: " `python /etc/scanbuttond/convert_scan.py $DESTFOLDER` rm $DESTINATION } ...
2çªç®ã®ã¹ã¯ãªãã
import os import sys # ... directory = sys.argv[1]
ç¬èªã®ã¹ã¯ãªããããããã°ããã«ã¯ãäœæ¥ç°å¢ã§æ¬¡ã®äžé£ã®ã³ãã³ããå®è¡ããããšããå§ãããŸãã
service scanbuttond stop sudo -u saned scanbuttond -f & tail -f /var/log/messages & tail -f /var/log/daemon.log &
ãŸããã¹ã¯ãªããã§echoãloggerãprintïŒPythonçšïŒã䜿çšããŸãã
3ã€ãã¹ãŠã®ã¹ã¯ãªãããå®è¡ãã³ãŒãã®çŸãããã€ã³ãã³ããã¹ãã«ããããã¯ãã¶ã€ã³ãã³ãŒããšããžãã¯ã®äžé©åãªæ £è¡ããœãªã¥ãŒã·ã§ã³ã®é¢é£æ§ãè¿œå ã®å¯èœæ§ãèè ã®åŠ¥åœæ§ãªã©ã«é¢ããæ¹å€ãæè¿ããŸãã
UPDïŒ
ãã°ãããããšããã®BASHã¹ã¯ãªããã¯ããªãæªããªããŸãããéåžžã®ãšã©ãŒåŠçãéå§ã§ããŸããã§ããã 圌ã¯åãåºããã¹ã¯ãªãããPythonã§æžãçŽããŸããã æçµçã«ã¯ããã«è¯ããªããŸãã å©ç¹-ãšã©ãŒåŠç+éåžžã®ãã°ããªãŒãã£ãªã¢ã©ãŒããçŸããã³ãŒãã®ããã«æãã=ïŒ ãã¡ãããå ¥æã§ããŸãã readmeã«ã¯ã€ã³ã¹ããŒã«æ å ±ãå«ãŸããŠããŸãã ãã¹ãŠãã¹ã ãŒãºã«æ©èœããŸã...ãŸããäœããæ©èœããªãå Žåã¯ã=ïŒã«ãç¥ãããã ãã