Help w/ creator changer script
Help w/ creator changer script
- Subject: Help w/ creator changer script
- From: Harold Bert Martin <email@hidden>
- Date: Fri, 14 Dec 2001 15:15:40 -0700
I wrote a drag-n-drop script for changing the creator types of files.
When a file (as opposed to folder) is dropped on it, it gives me errors
about either memory(stack overflow) or string(alias) types. I solved the
alias problem with the folders (as you can see in the code), but when I do
this in the file routine, it gives me the memory errors I referred to. I
have not tested this in OS X.
Here's a script(some of the long lines of code might be cut off. If you want
me to email it to you as an attachment, I will.):
--
global saved_types
global saved_creator
on run --This is double-clicked
set pick_choice to choose folder with prompt "Choose the folder with the
types you want me to set:" --Choose the folder with the files to change
change_it(pick_choice) --Run sub-routine
end run
on change_it(the_choice)
display dialog "What creator type do you want me to set the files to? "
default answer "Type four letter code here" with icon note --The creator
type to set the files to
set creator_code to the text returned of the result
repeat while the length of the creator_code is not 4 --A real creator
code has not been entered
beep (beep)
display dialog "What creator type do you want me to set the files
to? To quit, press cancel" default answer "Remember, type a four letter code
here." with icon note
set creator_code to the text returned of the result
end repeat
display dialog "How do I determine which files to alter?" buttons {"File
Type", "Creator Type", "Both"} with icon note default button "File Type"
--Chose how to select te files to change
set button_pressed to the button returned of the result
if the button_pressed is "File Type" then
display dialog "Type the file type of the files you want me to
change in the chosen folder:" default answer "Type four letter code here"
with icon note
set chosen_type to the text returned of the result
repeat while the length of the chosen_type is not 4
beep (beep)
display dialog "Type the file type of the files you want me to
change in the chosen folder:" default answer "Remember, type a four letter
code here." with icon note
set chosen_type to the text returned of the result
end repeat
set x to 0
tell application "Finder"
set the_choice to the_choice as alias --This is needed if the
script is dropped on. Otherwise, it creates an error.
set all_files to every item of the_choice whose file type =
chosen_type
repeat with x from 1 to the count of all_files --Here's where
all the files get changed
set the creator type of item x of all_files to creator_code
end repeat
end tell
beep
display dialog "Creator type set for " & x & " files in folder:" &
the_choice buttons {"OK"} default button "OK"
else if the button_pressed is "Creator Type" then
display dialog "Type the creator type of the files you want me to
change in the chosen folder:" default answer "Type four letter code here"
with icon note
set chosen_type to the text returned of the result
repeat while the length of the chosen_type is not 4
beep (beep)
display dialog "Type the creator type of the files you want me
to change in the chosen folder:" default answer "Remember, type a four
letter code here." with icon note
set chosen_type to the text returned of the result
end repeat
set x to 0
tell application "Finder"
set the_choice to the_choice as alias
set all_files to every item of the_choice whose creator type =
chosen_type
repeat with x from 1 to the count of all_files
set the creator type of item x of all_files to creator_code
end repeat
end tell
beep
display dialog "Creator type set for " & x & " files in folder:" &
the_choice buttons {"OK"} default button "OK"
else if the button_pressed is "Both" then
display dialog "Type the creator type of the files you want me to
change in the chosen folder:" default answer "Type four letter code here"
with icon note
set chosen_creator_type to the text returned of the result
repeat while the length of the chosen_creator_type is not 4
beep (beep)
display dialog "Type the creator type of the files you want me
to change in the chosen folder:" default answer "Remember, type a four
letter code here." with icon note
set chosen_creator_type to the text returned of the result
end repeat
display dialog "Type the file type of the files you want me to
change in the chosen folder:" default answer "Type four letter code here"
with icon note
set chosen_file_type to the text returned of the result
repeat while the length of the chosen_file_type is not 4
beep (beep)
display dialog "Type the file type of the files you want me to
change in the chosen folder:" default answer "Remember, type a four letter
code here." with icon note
set chosen_file_type to the text returned of the result
end repeat
set x to 0
tell application "Finder"
set the_choice to the_choice as alias
set all_files to every item of the_choice whose creator type =
chosen_creator_type and file type = chosen_file_type
repeat with x from 1 to the count of all_files
set the creator type of item x of all_files to creator_code
end repeat
end tell
beep
display dialog "Creator type set for " & x & " files in folder:" &
the_choice buttons {"OK"} default button "OK"
else
display dialog "Error in choice processing. Please contact software
author." with icon stop buttons {"OK"} default button "OK"
end if
end change_it
on open drop_choice --The script is dropped on
if last character of (drop_choice as text) is ":" then --It's a folder
repeat with x from 1 to the count of drop_choice --There might be
multiple folders
change_it(item x of drop_choice)
end repeat
else --This is the loop where I've been having problems
display dialog "What creator type do you want me to set the files
to?" default answer "Type four letter code here" with icon note
set creator_code to the text returned of the result
repeat while the length of the creator_code is not 4
beep (beep)
display dialog "Type the creator type of the files you want me
to change in the chosen folder:" default answer "Remember, type a four
letter code here." with icon note
set creator_code to the text returned of the result
end repeat
repeat with x from 1 to the count of drop_choice
set the creator type of item x of drop_choice to creator_code
--This is THE problem. It either generates "Stack overflow" errors of alias
errors
end repeat
display dialog "Creator type set for " & x & " files." buttons
{"OK"} default button "OK"
beep (beep)
end if
end open
--
Thanks,
H. Martin
email@hidden