I must be smoking something

I can’t get this to work


set temppath to ("" & (path to desktop) & "temp")
set JobName to "foo log.txt"
set AutoPath to ("" & (path to desktop) & "test")
tell application "Finder"
	set foo to files of folder temppath
	
	move file JobName of folder temppath to folder AutoPath with replacing
end tell

what am I doing wrong ?

Browser: Firefox 1.5.0.2
Operating System: Mac OS X (10.4)

Try:


set temppath to (((path to desktop) as string) & "temp")
set JobName to "foo log.txt"
set AutoPath to (((path to desktop) as string) & "test")

worked fine for me.

If there folders shouldn’t they end with colon?

set temppath to (path to desktop) & "temp:" as text
set JobName to "foo log.txt"
set AutoPath to (path to desktop) & "test:" as text
tell application "Finder"
	set foo to files of folder temppath
	move file JobName of folder temppath to folder AutoPath with replacing
end tell

still no luck

here are the results:


tell application "Finder"
	get every file of folder "Macintosh HD:Users:mcgrail:Desktop:temp"
		{document file "foo log.txt" of folder "temp" of folder "Desktop" of folder "mcgrail" of folder "Users" of startup disk, document file "RMN WC graphX" of folder "temp" of folder "Desktop" of folder "mcgrail" of folder "Users" of startup disk}
	move file "foo log.txt" of folder "Macintosh HD:Users:mcgrail:Desktop:temp" to folder "Macintosh HD:Users:mcgrail:Desktop:test" with replacing
		"Finder got an error: Can't get file \"foo log.txt\" of folder \"Macintosh HD:Users:mcgrail:Desktop:temp\"."

that worked fine for me too, though excluding the “:” in “temp:” and “test:” worked fine as well. This may be a dumb question, but is that standard for directories?

hmm…

works fine on my MBP but not on G5 ? :mad:

Hi Mark,

the default text class of file and folder names is Unicode text, only text results styled text (RTF)

@mcgrailm: I would try it with coercing the folders to aliases:

set temppath to (path to desktop as Unicode text) & "temp:" as alias
set JobName to "foo log.txt"
set AutoPath to (path to desktop as Unicode text) & "test:" as alias
tell application "Finder"
	set foo to name of files of temppath
	if foo contains {JobName} then
		move file JobName of temppath to AutoPath with replacing
	end if
end tell

PS: Mark’s script works also on my G5 :wink:

StefanK,

The unicode text is what seems to do the trick although I’m am not sure why. seems like allot or for next to nothing.

anyhow thank you all for your help

here is the final code I went with


set temppath to "" & (path to desktop as Unicode text) & "temp:"
set JobName to "foo log.txt"
set AutoPath to "" & (path to desktop as Unicode text) & "test:"
tell application "Finder"
	move file (temppath & JobName) to AutoPath with replacing
end tell

StefanK, both with and without colon worked for me on G5. I quite often keep paths as text or string then coerce to alias later. Are you saying that using “Unicode text” is a safer option and a good habit to start enforcing? Are there changes with either the OS or the Processor that affects this, that I should know about and don’t? Im X.3.9 BTW and no Intels yet.

I don’t know why the original script didn’t work for mcgrailm. It works for me. :confused:

With OS X, it’s a good idea to use Unicode text rather than strings for paths, as it’s possible for file and folder names to contain Unicode-only characters. These would be lost if coerced to string and the resulting path would then be useless.

There’s no need for the “” here. Its purpose in the original script was to cause the coercion of the ‘path to’ alias to string. It’s an inefficient method that dates from a few years ago. Compare these:

"" & (path to desktop)
--> 'path to' returns an alias.
--> The alias is concatenated to an empty string and is
--> implicitly coerced to string as part of that process.

-- Better:
(path to desktop) as string
--> 'path to' returns an alias.
--> The alias is explicity coerced to string. No concatenation.

-- Best:
(path to desktop as string) -- Using 'path to's optional 'as' parameter.
--> 'path to' returns a string. No coercion and no concatenation.

Stefan’s use of the ‘path to’ command returns the Unicode text directly.

NG thank you for the explanation. I will be explicity coerced to smoke out side in 24 days or run the risk of loss of £’s even though I’ve paid my Unicode tax directly!!

NG,

That was an extremely helpful explanation and I think … although I have tested yet…it explains the difference in why it doesn’t work on the G5

so I guess next time i use “path to” I will include as unicode text.

thank you all for your help

mm