• 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: AS how to check if a file name matches a string in a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AS how to check if a file name matches a string in a text file


  • Subject: Re: AS how to check if a file name matches a string in a text file
  • From: Ted Wrigley <email@hidden>
  • Date: Sun, 29 Jun 2014 12:21:04 -0700


On Jun 29, 2014, at 12:00 PM, email@hidden wrote:

From: Jim Weisbin <email@hidden>
Subject: AS how to check if a file name matches a string in a text file
Date: June 29, 2014 at 9:28:56 AM PDT
To: email@hidden


Hello. I’m fairly comfortable writing AS, but not an expert by any means.

I need to be able to do the following, and am looking for some pointers before I begin:

Open a text document (read-only is fine). The document will always be RTF format, created with TextEdit, so I think that precludes any kind of shell scripting to search it’s contents.

Open a folder and iterate through the filenames there (filenames only, no paths. That part is easy).

For each file name, see if it that exact name matches a line of text in the text doument. Lines are paragraphs with the normal Unix delimiters I think (not sure how it’s done in RTF).

Final dialog box will show a list of all matched filenames and total number of files dropped on the AS app.

My biggest question is, should I try to do this via TextEdit’s AS dictionary, or is there another way I should be thinking about?

I could insist that the text doument be plain text instead, if that makes it much easier.

If you want to do this with applescript, it’s easiest to convert the document to plain text first:

-- get the file names from the document as an AS list
set doctxt to paragraphs of (do shell script "textutil -convert txt -stdout  '/path/to/doc.rtf'")

tell application "System Events"
-- get the file names from the system
set fileNames to name of files of folder "/path/to/folder"
end tell

set foundFiles to {}
repeat with thisFileName in fileNames
-- compare filenames and store results
if thisFileName is in doctxt then copy thisFileName to end of foundFiles
end repeat

--convert found files list to text and display
set {oldTID, my text item delimiters} to {my text item delimiters, return}
set displayText to foundFiles as text
set my text item delimiters to oldTID
display dialog displayText
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: AS how to check if a file name matches a string in a text file
  • Next by Date: Re: AS how to check if a file name matches a string in a text file
  • Previous by thread: Re: AS how to check if a file name matches a string in a text file
  • Next by thread: Re: AS how to check if a file name matches a string in a text file
  • Index(es):
    • Date
    • Thread