How can I pass a counter result out of a script object
How can I pass a counter result out of a script object
- Subject: How can I pass a counter result out of a script object
- From: Mark Clyma <email@hidden>
- Date: Fri, 14 Nov 2003 13:06:15 -0600
Scripters,
I have an applescript droplet that uses Jon's Commands X 3.0 to walk a
given folder and its associated sub-folders and files. I want the
script to process only the text files that end in ".php". I then want
the script to use BBEdit to take the collected ".php" text files and
open each one and search for a "xml" tag and then delete the tag line
and save, close the file. Then process the rest of the collected ".php"
files the same way. I can get the script to work very well but I can
not figure how to "display dialog", at the very end of the script when
the processing is done, the variable "gfileUpdated" (this line in the
script: "set gfileUpdated to gfileUpdated + 1", found in the middle of
the script in a "if" statement). The "gfileUpdated" variable holds the
number of files updated (the number of ".php" files whose "xml" tag line
was deleted). When I try to display the variable at the end of the
script I always end up with zero (0). I have tried several things to
get the script to display the correct number of files updated but
nothing seems to work. Does anyone have a solution?
Also, does anyone know how to make the windows in BBEdit to not display
each time they are processed? Each file quickly flashes on the screen.
I would like BBEdit to work in the background if possible
Here is the script. I just drop the folder I want to process on top of
this AS droplet.
Thanks, Mark
property gFileExtToSave : {".php"}
property gTagToDelete : "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
property gfileUpdated : 0
on open (theFiles)
script foo
property FileList : {}
property gfileUpdated : 0
on open theFile
set tSourceFileName to a reference to theFile as string
if tSourceFileName ends with gFileExtToSave then
copy theFile as string to end of FileList
tell application "BBEdit"
activate
open {file tSourceFileName} with LF translation
-- make sure the "find" line includes a line feed
(return)
set findText to find "<?xml version=\"1.0\"
encoding=\"US-ASCII\"?>
" searching in text 1 of text window 1 options {search mode:literal,
starting at top:true, wrap around:false, reverse:false, case
sensitive:false, match words:false, extend selection:false} with
selecting match
if found of findText is true then
cut selection
save text window 1
-- collect the number of files updated
set gfileUpdated to gfileUpdated + 1
end if
close text window 1
end tell
end if
return FileList
end open
end script
set fl to walk folders theFiles with script foo with using files
without invisibles
display dialog (number of items of fl) as string
-- display the number of files updated
display dialog "The number of files that had the xml line deleted
was: " & gfileUpdated
quit application "BBEdit"
end open
_______________________________________________
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.