Bypass a make new folder if one already exists

Hello!
happy 4th of July to everyone out there is script land!!

I have a script that places any fla file on my desktop in a specific folder that the script makes.

tell application "Finder"
	
	set the current view of the front Finder window to list view
	set this_folder to make new folder at front Finder window with properties {name:"Flash desktop"}
	move (every document file of the front Finder window whose kind ends with "Flash Document") to this_folder
end tell

It works fine, the first time around. If I wanted to keep cleaning off my desktop of fla files, using this script, I can only use it once, because it says the folder already exists. I was trying to use the “if folder doesn’t exist” script stuff, but nothing is working.

How can I set it up so if the folder already exists, just move of the files?

thanks
babs

Hi,

first of all, if you want to address the desktop, why do you use “Finder window”?
The desktop can be accessed directly


property flashFolder : "Flash desktop"

-- the desktop folder of the current user is the "root" folder of the Finder
tell application "Finder"
	if not (exists folder flashFolder) then make new folder with properties {name:flashFolder}
	move (every document file whose kind ends with "Flash Document") to folder flashFolder
end tell


Hi Stefen,

That is how it was written in the book…Now you know why I keep reading the book and occasionally jumping on here for more help. Not only do my questions get answered, but I am learning better and more clearer ways to accomplish things :wink:

thanks for your help!!! As always :lol:
babs

read a more practical book :wink:

got any suggestions???
:stuck_out_tongue:

Hanaan Rosenthal: AppleScript: A Comprehensive Guide (more practical)
Matt Neuburg: AppleScript: The Definitive Guide (more technical, I regard this book as the “bible” of AppleScript)

Great!!!
thanks…I actually have both of those…of course that is not the one I am reading…LOL

I know, I have both, too :wink:

Hello Barbara.

Maybe this is something for you?

Thought that I’d mention that the AppleScript Language Guide (free) is a very good book about AppleScript.
You can download it for free at apple.com from here.

When I started scripting I found Appendix A in AppleScript The Definitive Guide tremendously useful.

Best regards

McUsr

Hi McUsr…
Great…thanks for the tip…I will download the guide and check out that index, as I do have that book :wink:
babs

Ha!
That’s my bookshelf too!

And mine. Both are essential to a deep understanding of AppleScript. I have others that predate them, but those are the two I always turn to, and although my copy is nearly 3 years old now, another great book for understanding how OS X works is Mac OS X Internals: A Systems Approach by Amit Singh. It was written in 2007, but is still relevant. Amazon has some used for $35.

Hello.

I don’t have Rosenthal. I should have had it I know. -On the other hand: the articles at MacScripter.net bout suffice and outgrows most of what can be found between the covers of a book. But of course: the nuggets aren’t that concentrated here, demanding more of the AppleScript Student.

I feel that AppleScript The Definitive Guide is for experienced scripters (excluding Appendix A).

But all of those resources are quite in depth whereas The AppleScript Language Guide might not be nitpicking on every detail and therefore provide and overall more concise overview of the language for the not so experienced scripter. That’s just my opinon

One book I really liked as an intro to AppleScript was Adam Goldsteins “AppleScript The Missing Manual”.
He totally changed my mind of what a 14 year old kid was capable of. It is light and witty, and gives a good over all coverage without too many utterly stupid examples and exercises. To reading it was a joyful experience.

Doing it and playing with it is as important as reading about it.

Hind sightly the first thing I should have done was to run out and by ScriptDebugger the first day I started scripting.
Those (really not that many) bucks would have saved me lots of time, and aggravating experiences.

Best Regards

McUsr

Rosenthal’s book has been revised by Hamish Sanderson, and has been released under the slightly revised title ‘Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X’. There’s quite a lot of new stuff in there (it now tops 1000 pages), including a chapter on AppleScriptObjC by Craig Williams.

Disclaimer: I wrote a chapter of it too (on InDesign), although I don’t get any more money if you all rush out and buy it…

Hello.

I’ll get my hands on it.

Best Regards

McUsr