Help! Need to move folder contents with applescript.

Discussion in 'Mac Programming' started by Littleodie914, Jul 21, 2005.

  1. Littleodie914 macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    Hey guys, Tiger just came in the mail yesterday, and I'm having a ball! :D I'm trying to get an automator application ready for my mom which will download the pictures from her digital camera, move them to a specific dated folder, and scale them to 300 pixels. Here's what I've got so far:
    Code:
    on run {input, parameters}
    	tell application "Finder"
    		set mydate to day of (current date) as string
    		set mymonth to month of (current date) as string
    		if exists folder "Macintosh HD:Users:Craig:Pictures:eBay Temp:" then
    		else
    			make new folder at "Macintosh HD:Users:Craig:Pictures:" with properties {name:"eBay Temp"}
    		end if
    		if exists folder "Macintosh HD:Users:Craig:Pictures:Pictures:" then
    		else
    			make new folder at "Macintosh HD:Users:Craig:Pictures:" with properties {name:"Pictures"}
    		end if
    		
    		
    		set unknownfolder to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & ":"
    		try
    			alias unknownfolder
    		on error
    			try
    				make new folder at "Macintosh HD:Users:Craig:Pictures:Pictures:" with properties {name:"untitled1"}
    				set name of folder "Macintosh HD:Users:Craig:Pictures:Pictures:untitled1:" to mymonth
    			on error
    				
    			end try
    		end try
    		
    		set unknownfolder2 to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & mydate & ":"
    		
    		try
    			alias unknownfolder2
    		on error
    			try
    				make new folder at ("Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth) with properties {name:"untitled2"}
    				set nwpath to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & ":"
    				set name of folder (nwpath & "untitled2:") to mydate
    			end try
    		end try
    		set mydate1 to day of (current date)
    		set mymonth1 to month of (current date)
    		set localFolder to "Macintosh HD:Users:Craig:Pictures:eBay Temp:"
    		set remoteFolder to ("Macintosh HD:Users:Craig:Pictures:Pictres:" & mymonth1 & mydate1)
    		move every file of folder localFolder to folder remoteFolder with replacing
    	end tell
    	return input
    end run
    What it basically does is create a folder in the pictures folder with todays month, then creates a folder inside that with the day of the month, then moves all the pictures in there. The only part I'm having trouble with is the last bit where it moves the files. (Fourth to last line.) When running the script, I get:
    "Finder got an error: Can't set folder 'Macintosh HD:Users:Craig:pictures:pictures:July21' to every file of folder "Macintosh HD:Users:Craig:pictures:eBay Temp:".

    Any ideas? :confused:
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    When you append several variables to a folder string, you need to separate them with colons so they are treated as separate folders.

    eg
    Code:
    set unknownfolder2 to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & mydate & ":"
        -->"Macintosh HD:Users:Craig:Pictures:Pictures:July21:"
    Should be
    Code:
    set unknownfolder2 to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & ":" & mydate & ":"
        -->"Macintosh HD:Users:Craig:Pictures:Pictures:July:21:"
    Similarly
    Code:
    set remoteFolder to ("Macintosh HD:Users:Craig:Pictures:Pictres:" & mymonth1 & mydate1)
    Should be (note the "Pictres" typo is also fixed)
    Code:
    set remoteFolder to ("Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth1 & ":" & mydate1)
    With the above changes, here's the new code:
    Code:
    on run {input, parameters}
    	tell application "Finder"
    		set mydate to day of (current date) as string
    		set mymonth to month of (current date) as string
    		if exists folder "Macintosh HD:Users:Craig:Pictures:eBay Temp:" then
    		else
    			make new folder at "Macintosh HD:Users:Craig:Pictures:" with properties {name:"eBay Temp"}
    		end if
    		if exists folder "Macintosh HD:Users:Craig:Pictures:Pictures:" then
    		else
    			make new folder at "Macintosh HD:Users:Craig:Pictures:" with properties {name:"Pictures"}
    		end if
    		
    		
    		set unknownfolder to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & ":"
    		try
    			alias unknownfolder
    		on error
    			try
    				make new folder at "Macintosh HD:Users:Craig:Pictures:Pictures:" with properties {name:"untitled1"}
    				set name of folder "Macintosh HD:Users:Craig:Pictures:Pictures:untitled1:" to mymonth
    			on error
    				
    			end try
    		end try
    		
    		set unknownfolder2 to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & ":" & mydate & ":"
    		
    		try
    			alias unknownfolder2
    		on error
    			try
    				make new folder at ("Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth) with properties {name:"untitled2"}
    				set nwpath to "Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth & ":"
    				set name of folder (nwpath & "untitled2:") to mydate
    			end try
    		end try
    		set mydate1 to day of (current date)
    		set mymonth1 to month of (current date)
    		set localFolder to "Macintosh HD:Users:Craig:Pictures:eBay Temp:"
    		set remoteFolder to ("Macintosh HD:Users:Craig:Pictures:Pictures:" & mymonth1 & ":" & mydate1)
    		move every file of folder localFolder to folder remoteFolder with replacing
    	end tell
    	return input
    end run
     
  3. Littleodie914 thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #3
    Woo hoo! :eek:

    Thanks so much for the help, I really appreciate it! I've had a bit of applescript experience in the past, but not enough to know that much about dealing with variables in file paths. The script works great now, my mom sends her thanks ;)
     

Share This Page