image - Applescript: Counting the number of JPG files in subfolders -


update: here's current code, returns 0, when selecting folder of jpg images

set f (choose folder) set posixf posix path of f set result shell script "find " & posixf & " -iname \"*.jpg\" | wc -l"  display dialog result 

i need way count of jpg files in collection of different folders. these folders organized so: outermost folder -> object folder -> either scans (containing jpg files) or originals (containing tiff files). outer folder can have hundreds of object folders inside, hence need script count files.

i have looked around applescript solution , closest have come counts number of jpgs in single folder, not subfolders. if drop outermost folder on application, output of 0, if drop 1 of internal scans folders, 10 (the actual number of jpg files in test folder)

here have far:

global currentcount on open droppings set nooffiles 0 repeat everydrop in droppings     if (info everydrop)'s folder true         tell application "finder"             set currentcount (count of (files in folder everydrop name extension "jpg")) integer             set nooffiles nooffiles + currentcount         end tell         display dialog nooffiles     end if end repeat end open  on run display dialog "drop folders onto application count number of jpg files" buttons {"ok"} default button "ok" end run 

i have tried adding of code automator "get folder contents" , "repeat each subfolder found" option checked, errors saying applescript "couldn't make alias... something.tif type folder".

updated 1 more time :-)

this seems work...

set f (choose folder) set posixf posix path of f display dialog posixf posixf set cnt shell script "find " & quoted form of posixf & " -type f | wc -l" cnt display dialog cnt 

i use say debugging.

updated answer

you can result of shell script applescript variable this:

set result shell script "find . -iname \"*.jpg\" | wc -l" result 

you can pass applescript variable shell script this:

set var "/tmp/*" set result shell script "find " & var & " | wc -l" result 

you can allow user choose folder with:

set f (choose folder) set posixf posix path of f posixf 

original answer

you can use shell , find command you. start terminal , type command find names of jpeg files in home directory:

find $home -iname "*.jpg" -print 

that says... starting @ $home, find files names end in jpg (or lowercase variant of that) , print names.

the -iname means case-insensitive name, whereas -name require case match exactly.

now, if want jpeg files in /usr as well, add in this:

find /usr $home -iname "*.jpg" -print 

and if want count files, ask wc (the word count program) count lines of output this:

find /usr $home -iname "*.jpg" -print | wc -l 

so, can wrap in do shell script inside applescript , answer. may encounter errors if there files cannot access, discard them bit-bucket this:

find /usr $home -iname "*.jpg" -print 2> /dev/null | wc -l 

you add in -type f count files, doesn't count directories called imagesinjpg if have such beasts on mac.

note can replace "*.jpg" \*.jpg if makes applescripting easier.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -