Re: Newbie FaceSpan/Applescript question
Re: Newbie FaceSpan/Applescript question
- Subject: Re: Newbie FaceSpan/Applescript question
- From: Chad Gray <email@hidden>
- Date: Wed, 13 Dec 2000 14:36:49 -0500
(i resent this because it looked like the formatting got all messed up...
sorry)
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 statements?
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"
activate
display dialog "Should this script trim the names of files, folders, or
both?" buttons {"Files", "Folders", "Both"}
set the target_type to the button returned of the result
repeat
try
display dialog "The number of characters to trim from every file name:"
default answer "0" buttons {"Cancel", "Trim Start", "Trim End"}
copy the result as list to {the character_count, the button_pressed}
if the character_count is not "" then
set the character_count to the character_count as integer
if the character_count is not 0 then exit repeat
end if
on error
end try
end repeat
set the source_folder to choose folder with prompt "Folder of items to trim:"
if the target_type is "Files" then
set the matching_items_list to (every file of the source_folder) as list
else if the target_type is "Folders" then
set the matching_items_list to (every folder of the source_folder) as list
else
set the matching_items_list to (every item of the source_folder) as list
end if
if the matching_items_list is {} then
beep
display dialog "There are no items in the chosen folder." buttons
{"Cancel"} default button 1
end if
repeat with this_file in the matching_items_list
set the current_name to name of this_file
try
if the button_pressed is "Trim Start" then
set the new_name to (characters (the character_count + 1) thru -1 of
the current_name) as string
else
set the new_name to (characters 1 thru -(the character_count + 1) of
the current_name) as string
end if
my set_file_name(this_file, the new_name)
on error
end try
end repeat
end tell
beep 2
on set_file_name(this_file, new_file_name)
tell application "Finder"
activate
set the parent_container_path to (the container of this_file) as text
if not (exists item (the parent_container_path & new_file_name)) then
try
set the name of this_file to new_file_name
on error the error_message number the error_number
if the error_number is -59 then
set the error_message to "This name contains improper characters, such
as a colon (:)."
else --the suggested name is too long
set the error_message to "The name is more than 31 characters long."
end if
beep
display dialog the error_message default answer new_file_name buttons
{"Cancel", "Skip", "OK"} default button 3
copy the result as list to {new_file_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_file_name(this_file, new_file_name)
end try
else --the name already exisits
beep
display dialog "This name is already taken, please rename." default
answer new_file_name buttons {"Cancel", "Skip", "OK"} default button 3
copy the result as list to {new_file_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_file_name(this_file, new_file_name)
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
display dialog "This is your project!"
else if theMenu is "File" then
if theMenuItem = "Quit" then
quit
end if
end if