T's Blog RSS

I'm Terence Pua. I helped build Bandwagon and iTenna.

View Terence Pua's profile on LinkedIn

Archive

Jun
19th
Tue
permalink

AppleScript hack: move screenshots from Desktop to iPhoto

on text_to_list(txt, delim)
    set saveD to AppleScript’s text item delimiters
    try
        set AppleScript’s text item delimiters to {delim}
        set theList to every text item of txt
    on error errStr number errNum
        set AppleScript’s text item delimiters to saveD
        error errStr number errNum
    end try
    set AppleScript’s text item delimiters to saveD
    return (theList)
end text_to_list


———
on change_case(this_text, this_case)
    if this_case is 0 then
        set the comparison_string to “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
        set the source_string to “abcdefghijklmnopqrstuvwxyz”
    else
        set the comparison_string to “abcdefghijklmnopqrstuvwxyz”
        set the source_string to “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
    end if
    set the new_text to “”
    repeat with this_char in this_text
        set x to the offset of this_char in the comparison_string
        if x is not 0 then
            set the new_text to ¬
                (the new_text & character x of the source_string) as string
        else
            set the new_text to (the new_text & this_char) as string
        end if
    end repeat
    return the new_text
end change_case
———

set the_command to “mdfind -onlyin ~/Desktop/ "kMDItemContentTypeTree = ‘*public.image*’wc"”
set text_return to (do shell script the_command)
set returned_list to text_to_list(text_return, return)
set totaltext to {}
repeat with an_image in returned_list
    try
        set this_file to (an_image as string)
        set small_file to change_case(this_file, 0)
       
        if (small_file ends with “png”) or (small_file ends with “gif”) or (small_file ends with “jpg”) or (small_file ends with “tiff”) then
            set totaltext to totaltext & this_file
        end if
        —display dialog this_file
    on error errorstr
        display dialog errorstr
    end try
end repeat

if (totaltext is not equal to “”) then
    tell application “iPhoto”
        import from totaltext
    end tell
end if