Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Applescript: different scope rules for drag-and-droplets?

Applescript: different scope rules for drag-and-droplets?
Thread Tools
Since EBCDIC
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Jun 28, 2007, 07:38 AM
 
I'm trying to write a script which renames *folders* from "xxx_MMDD" to "YYYY-MM-DD" (to ease digital photo management). I'm told that a drag-and-drop applet is the thing which I need to add as a folder action. What's bedeviling me is that variable xyzzy is not defined at the display dialog. Either there's some dumb typo or I don't grok the scope rules. Hep', pls.

on open theseItems
tell application "Finder"
repeat with thisItem in theseItems
if kind of thisItem is "folder" then

try
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set xyzzy to last text item of thisItem
set AppleScript's text item delimiters to oldDelims
on error
set AppleScript's text item delimiters to oldDelims
end try

display dialog xyzzy -- fails; why?

end if
end repeat
end tell
end open
Since EBCDIC
Using Macs since they were Lisas.
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jun 28, 2007, 11:08 PM
 
Taking a quick look I think the problem is that you are trying to use a refernce to a folder as if it were a string. You need to explicitly "set thisPath to path to thisItem as text", and then split thisPath.
     
Since EBCDIC  (op)
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Jun 29, 2007, 01:57 AM
 
Thanks for the reply. I figured it was something like that (as it's been many years since I've done any Applescripting), but alas, either I didn't grok your hint or we're both off the beam. Saving the following as an app, and dropping an empty folder named "123_1221" onto the app, results in two strange behaviours: (1) there's no output from the first display dialog, and the latter throws an "thisPath not defined" error. Grrr.

-- For a droplet, you use a special handler called an open handler…
on open theseItems
tell application "Finder"
repeat with thisItem in theseItems
if kind of thisItem is "folder" then

try
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}

set thisPath to path to thisItem as text
set xyzzy to last text item of thisPath

display dialog "in: " & xyzzy -- fails: no output; why?

set AppleScript's text item delimiters to oldDelims
on error
set AppleScript's text item delimiters to oldDelims
end try

display dialog "out: " & thisPath -- fails, thisPath not defined; why?

-- Convert folder names "xxx_MMDD" to "YYYY-MM-DD"
(*
set pixMonth to text 6 thru 7 of folderName
set pixDay to text 8 thru 9 of folderName
*)
else
display dialog "error: only folders, please."
end if
end repeat
end tell
end open
Since EBCDIC
Using Macs since they were Lisas.
     
itai195
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jun 29, 2007, 03:56 AM
 
Don't have the time to help with the AppleScript at the moment, but why not just use Automator for this? It's the kind of thing it was designed for.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 11:23 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,