Re: Creating a folder on the desktop
Re: Creating a folder on the desktop
- Subject: Re: Creating a folder on the desktop
- From: Andrew Oliver <email@hidden>
- Date: Tue, 06 Sep 2005 10:04:57 -0700
On 9/6/05 7:35 AM, "patrick machielse" <email@hidden> wrote:
> I can't get this to work
>
> tell application "System Events"
> make new folder at desktop folder
> end tell
>
> I tried dozens of variations, POSIX paths, 'with properties', etc.
> Mostly gives me NSContainerSpecifierError back, but 'desktop folder'
> is a good reference, or isn't it.
>
> After struggling with this for a _long_ time, I found that
>
> tell application "Finder"
> make new folder at desktop
> end tell
>
> does indeed do what I want.
>
> I'm an AppleScript newby, and this kind of thing really makes me
> loose faith in AS. I never felt this frustrated before when learning
> any real programming languages :-(
The Finder is generally responsible for all file/folder handling.
System Events handles just that - _system_ events. Creating a directory is
not a system function, hence the need to use the Finder (or some other app
that manages the file system.
>
> Some further madness:
>
> set myDesktop to folder "~/Desktop"
>
> works in System Events, but not in Finder. Why do System Events and
> Finder seem to duplicate functionality in an incompatible way? Is
> there any documentation on this stuff that I can read _before_ I
> loose my marbles?
For various reasons, the Finder requires Mac-style paths, so a more
appropriate way to do this in the Finder is:
tell application "Finder"
set myDesktop to folder "Desktop" of (path to home folder)
end tell
(note the use of 'path to home folder" to find the user's home directory
since you don't necessarily know their name)
Although it's far, far easier to bypass the Finder altogether and just use:
set myDesktop to path to desktop folder
Which works anywhere (doesn't even need the Finder) and will return an alias
object that you can use.
>
> Sorry if this is a bit of a rant, I should take a short break...
One of AppleScripts true strengths is its ability to leverage other
applications to do its work. It's real weakness is knowing which application
to target. There isn't much you can do about that other than practice.
Andrew
:)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden