moving files from desktop to created folder

Hi everyone, I am having a bit of a weird problem here… Not sure why…

I am getting the error ‘Can’t make “Desktop-4/18/064/18/06”’ into type integer." when I am trying to check to see if the folder exists… And I also get an error of “can’t get every file of desktop” once it passes that point.

If anyone can help, that would be great.


property foldername : "Desktop-"
tell application "Finder"
	set datestring to my date_time((current date) as string)
	set foldername to foldername & datestring
	set x to path to home folder from user domain as string
	set x to x & "iJunk"
	repeat
		if not (the folder (foldername as string) of x exists) then
			make new folder at x with properties {name:foldername}
			exit repeat
		end if
		set r to r + 1
		set foldername to foldername & "-" & r
	end repeat
	set y to POSIX path of x & "/" & foldername
	return y
	move every file of the desktop to y
	move every folder of the desktop to y
end tell
on date_time(datestring)
	set my_date to date datestring
	return short date string of my_date
end date_time


Thanks, it’s sort of working better but I still am having problems… I tweaked it a bit more…

One of the problems is, my iJunk folder is a symbolic link from my home directory to another hard drive… and I guess the “as alias” part of the script isn’t working because I am getting the error:

And if I set it to use a directory within my home which is not a symbolic link, then I get in the event log:

which I assume is because my hard drive volumes are “items” on my desktop (atleast I would imagine they are) and it’s trying to move those too… ???

here is the ‘tweaked’ script:

property foldername : ""
tell application "Finder"
	set datestring to my date_time((current date) as string)
	set foldername to "Desktop-" & datestring
	set x to path to home folder from user domain as string
	set x to x & "iJunk"
	set foldernameoriginal to foldername
	set r to 0
	repeat
		
		if not (exists folder foldername of folder x) then
			make new folder at x with properties {name:foldername}
			exit repeat
		end if
		set r to r + 1
		set foldername to foldernameoriginal & "-" & r
	end repeat
	set y to (x & ":" & foldername) as alias
	move items of the desktop to y
	return
end tell
on date_time(datestring)
	set my_date to date datestring
	return short date string of my_date
end date_time

Thanks so much for your help… Still one thing not working now-- If the folder exists, it’s not creating one with a number after it, it’s just giving me an error that it already exists…

I ended up changing the move items to use the shell, because apparently moving files from one drive to another doesn’t delete the items afterwards.

property foldername : ""
set the_desktop to (path to desktop)

tell application "Finder"
	set datestring to my date_time((current date) as string)
	set foldername to "Desktop-" & datestring
	set AppleScript's text item delimiters to "/"
	set temp to text items of foldername
	set AppleScript's text item delimiters to "-"
	set foldername to temp's text items as string
	set AppleScript's text item delimiters to ""
	set x to path to home folder from user domain as string
	set x to x & "iJunk"
	set foldernameoriginal to foldername
	set r to 0
	repeat
		if not (exists folder foldername of folder x) then
			make new folder at x with properties {name:foldername}
			exit repeat
		end if
		set r to r + 1
		set foldername to foldernameoriginal & "-" & r
	end repeat
	
	set y to (x & ":" & foldername)
	set y to "mv ~/Desktop/* " & POSIX path of y
	do shell script (y)
end tell

on date_time(datestring)
	set my_date to date datestring
	return short date string of my_date
end date_time

I did some testing with this script, and it turns out it works perfect if the folder is not a symbolic link.

can anyone tell me why this doesn’t work if “iJunk” is a symbolic link?

property foldername : ""
set the_desktop to (path to desktop)

tell application "Finder"
	set datestring to my date_time((current date) as string)
	set foldername to "Desktop-" & datestring
	set AppleScript's text item delimiters to "/"
	set temp to text items of foldername
	set AppleScript's text item delimiters to "-"
	set foldername to temp's text items as string
	set AppleScript's text item delimiters to ""
	set x to path to home folder from user domain as string
	set x to x & "iJunk"
	set foldernameoriginal to foldername
	set r to 0
	repeat
		if not (exists folder foldername of folder x) then
			make new folder at x with properties {name:foldername}
			exit repeat
		end if
		set r to r + 1
		set foldername to foldernameoriginal & "-" & r
	end repeat
	set y to (x & ":" & foldername)
	set y to "mv ~/Desktop/* " & POSIX path of y
	do shell script (y)
end tell

on date_time(datestring)
	set my_date to date datestring
	return short date string of my_date
end date_time

Thanks Jacques…

Unfortuantely I still have one problem!! If the hard drive contains special characters in the name, such as a space, this does not work. I added a character replacement subroutine, which I used in another terminal script I made-- which works perfect but for some alien reason, it’s not working correctly here! Can you explain why??

if theTarget =“Atari SH204:iJunk:Desktop-21-04-06-24:”

then after my charreplace section, theTarget becomes: “Atari\ SH204:iJunk:Desktop-21-04-06-24:”

Which makes absolutely no sense!! there should only be one backslash, and if I try to just put “\ " in the script, I get an error: “Expected “”” but found unknown token.” because applescript needs an escape character ""—which makes me scream because I don’t understand why two back slashes are showing up when I return theTarget.

I’d love an explanation for this!

tell application "Finder"
	set foldername to "Desktop-" & (do shell script "date \"+%d-%m-%y\"")
	set target_Link to ((path to home folder from user domain as string) & "iJunk:" as alias)
	set foldernameoriginal to foldername
	set r to 0
	repeat
		if not (exists folder foldername of target_Link) then
			set theTarget to (make new folder at target_Link with properties {name:foldername}) as alias
			exit repeat
		end if
		set r to r + 1
		set foldername to foldernameoriginal & "-" & r
	end repeat
	set theTarget to my charreplace({"\\", "!", "@", "$", "^", "&", "*", "(", ")", ";", "'", "{", "}", "[", "]", "|", "<", ">", "?", "\"", " "}, {"\\\\", "\\!", "\\@", "\\$", "\\^", "\\&", "\\*", "\\(", "\\)", "\\;", "\\'", "\\{", "\\}", "\\[", "\\]", "\\|", "\\<", "\\>", "\\?", "\\\"", "\\ "}, theTarget as Unicode text)
	set y to "mv ~/Desktop/* " & POSIX path of theTarget
	do shell script (y)
end tell
to charreplace(original, replacement, textfield)
	repeat with i from 1 to count original
		set text item delimiters to item i of original
		set textfield to listToText of me from textfield's text items between item i of replacement
		set text item delimiters to ""
	end repeat
	return textfield
end charreplace

on listToText from l between d
	set text item delimiters to d
	tell l to beginning & ({""} & rest)
end listToText

Thank you so much for your help!

works perfect!!