• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I pass a counter result out of a script object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I pass a counter result out of a script object


  • Subject: Re: How can I pass a counter result out of a script object
  • From: kai <email@hidden>
  • Date: Sat, 15 Nov 2003 02:11:58 +0000

on Fri, 14 Nov 2003 13:06:15 -0600, Mark Clyma wrote:

> 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?

Possibly, Mark (see below).

> 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

Don't tell it to activate. (However, the 'cut selection' command probably
won't work if it's not activated - so you may then need something like: set
selection to "".)

> Here is the script. I just drop the folder I want to process on top of
> this AS droplet.
>
> property gFileExtToSave : {".php"}
> property gTagToDelete : "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"

The 'gTagToDelete' property doesn't currently appear to be used in your
script. You could either delete it - or use it to replace the "<?xml...\"?>"
string in the BBEdit tell block below.

> property gfileUpdated : 0

The main script's 'gfileUpdated' property doesn't seem to be used either -
and could probably also be dispensed with. (However, script foo's
'gfileUpdated' below is another matter...)

> 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

To avoid BBEdit coming to the front, delete the 'activate' command...

> 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\"?>

If you keep the property 'gTagToDelete', then the above part of this line
could be rewritten as:

set findText to find gTagToDelete

(then continue the line with...)

> " 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

Since BBEdit probably won't be happy doing that in the background, try
replacing 'cut selection' with:

set selection to ""

> 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

Instead of 'return FileList', I'd suggest something like:

return {l:FileList, u:gfileUpdated}

> 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

Then you'll need to change the above statement along these lines:

display dialog (number of items of r's l) as string

...or just:

display dialog (count r's l)

> -- display the number of files updated
> display dialog "The number of files that had the xml line deleted was: " &
> gfileUpdated

Similarly, replace the above line with something like:

display dialog "The xml line was deleted in " & r's u & " lines."

> quit application "BBEdit"
> end open

---
kai
_______________________________________________
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.

  • Prev by Date: Re: Filtering Mail by content.
  • Next by Date: Font Panel
  • Previous by thread: How can I pass a counter result out of a script object
  • Next by thread: Re: How can I pass a counter result out of a script object
  • Index(es):
    • Date
    • Thread