Re: Rename Droplet Works in OS 9 But Not X
Re: Rename Droplet Works in OS 9 But Not X
- Subject: Re: Rename Droplet Works in OS 9 But Not X
- From: Andrew Oliver <email@hidden>
- Date: Thu, 03 Jul 2003 13:36:13 -0700
Why are you using 'selection' at all?
It is not a robust way of doing this because it's subject to change.
For example, what would happen if the user clicks the mouse again while your
droplet it loading? At best, the 'selection' would be empty and your script
would fail, at worst the user selected some other file and you've now
renamed something completely different.
The whole point of droplets is they *get passed* the files that were dropped
on them, so you can reference them directly and never have to worry about
the selection moving from under your feet.
As you've seen, you get passed a list of files (even if only one file was
dropped), so a better way to do this (sans error checking which is left up
to you):
on open theFiles -- remember, there might be more than one
tell application "Finder"
set name of (item 1 of theFiles) to "PEAC-SMG.xls
end tell
end open
This is completely insulated from anything the user does (bar deleting the
file) between when the files are dropped and when your script gets to run.
Andrew
:)
On 7/3/03 11:41 AM, "Ben Waldie" <email@hidden> wrote:
>
Micahel,
>
>
On Thursday, July 3, 2003, at 01:41 PM, Alatorre, Michael wrote:
>
>
> Here is a simple rename droplet that works in OS 9:
>
> on open theFile
>
> tell application "Finder"
>
> select theFile
>
> set name of selection to "PEAC-SMG.xls"
>
> end tell
>
> end open
>
> But, if I use the same code in OS X, I get this error:
>
>
>
> Can't set name of selection of application "Finder" to "PEAC-SMG.xls".
>
>
>
> If it's related to differences in the Finder, does anyone have a
>
> suggestion
>
> on how to accomplish this in X?
>
>
The problem here is that OS X is returning the selection as a list.
>
Also, when you use the "open" handler, the items dropped on the script
>
are also passed as a list. So, you need to be a little more specific.
>
>
There are a couple of ways to do this...
>
>
on open theFile
>
tell application "Finder"
>
select theFile
>
set theSelection to selection
>
set name of (item 1 of theSelection) to "PEAC-SMG.xls"
>
end tell
>
end open
>
>
OR
>
>
on open theFile
>
set theFile to item 1 of theFile
>
tell application "Finder"
>
select theFile
>
set name of theFile to "PEAC-SMG.xls"
>
end tell
>
end open
>
>
>
- Ben
>
>
Benjamin S. Waldie
>
Automated Workflows, LLC
>
=============================================
>
AppleScript and Workflow Automation
>
Consulting - <http://www.automatedworkflows.com>
>
AppleScript Info - <http://www.applescriptguru.com>
>
AppleScript Training - <http://www.applescripttraining.com>
>
=============================================
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.