Newbie FaceSpan/Applescript question
Newbie FaceSpan/Applescript question
- Subject: Newbie FaceSpan/Applescript question
- From: Chad Gray <email@hidden>
- Date: Wed, 13 Dec 2000 14:28:11 -0500
Im trying to make a button in Face Span that will run the Trim
Characters from File Names script i download from apple.com.
I setup a button and named it "trim".
I hit an error (expected "end" but found "on"). It is referring to the
line on set_file_name(this_file, new_file_name). Can i nest On
statments? that is the only thing i can think of...
Any help with this would be much appreciated! Im just starting to learn
this language. :)
Below is my application script. there isnt any scripts in the button
becuase i have not figured out how to use that yet. :)
on hilited theObj
-- TRIM CHARACTERS FROM ITEM NAMES
-- )2000 Sal Soghoian, Apple Computer
tell application "Finder"
& nbsp; activate
& nbsp;
& nbsp; display dialog "Should this script trim the names
of files, folders, or both?" buttons {"Files", "Folders", "Both"}
& nbsp; set the target_type to the button returned of the
result
& nbsp;
& nbsp; repeat
& nbsp; &nb sp; try
& nbsp; &nb sp; ; display dialog "The number
of characters to trim from every file name:" default answer "0" buttons
{"Cancel", "Trim Start", "Trim End"}
& nbsp; &nb sp; ; copy the result as list to
{the character_count, the button_pressed}
& nbsp; &nb sp; ; if the character_count is
not "" then
& nbsp; &nb sp; ; < /x-tab>set the
character_count to the character_count as integer
& nbsp; &nb sp; ; < /x-tab>if the
character_count is not 0 then exit repeat
& nbsp; &nb sp; ; end if
& nbsp; &nb sp; on error
& nbsp; &nb sp; end try
& nbsp; end repeat
& nbsp;
& nbsp; set the source_folder to choose folder with prompt
"Folder of items to trim:"
& nbsp;
& nbsp; if the target_type is "Files" then
& nbsp; &nb sp; set the matching_items_list to (every
file of the source_folder) as list
& nbsp; else if the target_type is "Folders" then
& nbsp; &nb sp; set the matching_items_list to (every
folder of the source_folder) as list
& nbsp; else
& nbsp; &nb sp; set the matching_items_list to (every
item of the source_folder) as list
& nbsp; end if
& nbsp; if the matching_items_list is {} then
& nbsp; &nb sp; beep
& nbsp; &nb sp; display dialog "There are no items in
the chosen folder." buttons {"Cancel"} default button 1
& nbsp; end if
& nbsp;
& nbsp; repeat with this_file in the matching_items_list
& nbsp; &nb sp; set the current_name to name of
this_file
& nbsp; &nb sp; try
& nbsp; &nb sp; ; if the button_pressed is
"Trim Start" then
& nbsp; &nb sp; ; < /x-tab>set the
new_name to (characters (the character_count + 1) thru -1 of the
current_name) as string
& nbsp; &nb sp; ; else
& nbsp; &nb sp; ; < /x-tab>set the
new_name to (characters 1 thru -(the character_count + 1) of the
current_name) as string
& nbsp; &nb sp; ; end if
& nbsp; &nb sp; ; my set_file_name(this_file,
the new_name)
& nbsp; &nb sp; on error
& nbsp; &nb sp; end try
& nbsp; end repeat
end tell
beep 2
on set_file_name(this_file, new_file_name)
tell application "Finder"
& nbsp; activate
& nbsp; set the parent_container_path to (the container of
this_file) as text
& nbsp; if not (exists item (the parent_container_path &
new_file_name)) then
& nbsp; &nb sp; try
& nbsp; &nb sp; ; set the name of this_file
to new_file_name
& nbsp; &nb sp; on error the error_message number the
error_number
& nbsp; &nb sp; ; if the error_number is -59
then
& nbsp; &nb sp; ; < /x-tab>set the
error_message to "This name contains improper characters, such as a colon
(:)."
& nbsp; &nb sp; ; else --the suggested name
is too long
& nbsp; &nb sp; ; < /x-tab>set the
error_message to "The name is more than 31 characters long."
& nbsp; &nb sp; ; end if
& nbsp; &nb sp; ; beep
& nbsp; &nb sp; ; display dialog the
error_message default answer new_file_name buttons {"Cancel", "Skip",
"OK"} default button 3
& nbsp; &nb sp; ; copy the result as list to
{new_file_name, button_pressed}
& nbsp; &nb sp; ; if the button_pressed is
"Skip" then return 0
& nbsp; &nb sp; ; my set_file_name(this_file,
new_file_name)
& nbsp; &nb sp; end try
& nbsp; else --the name already exisits
& nbsp; &nb sp; beep
& nbsp; &nb sp; display dialog "This name is already
taken, please rename." default answer new_file_name buttons {"Cancel",
"Skip", "OK"} default button 3
& nbsp; &nb sp; copy the result as list to
{new_file_name, button_pressed}
& nbsp; &nb sp; if the button_pressed is "Skip" then
return 0
& nbsp; &nb sp; my set_file_name(this_file,
new_file_name)
& nbsp; end if
end tell
end set_file_name
end hilited
on run --the application has been launched without any particular
document to open
open window "Untitled"
end run
on chosen theObj -- a menu item has been chosen
copy name of window of theObj to theWindow
copy name of theObj to theMenuItem
copy title of menu of theObj to theMenu
if index of menu of theObj = 1 then
& nbsp; display dialog "This is your project!"
& nbsp;
else if theMenu is "File" then
& nbsp; if theMenuItem = "Quit" then
& nbsp; &nb sp; quit
& nbsp; end if
end if