• 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: Populating a variable from a txt file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Populating a variable from a txt file


  • Subject: Re: Populating a variable from a txt file
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 16 Feb 2012 03:56:54 -0600

On Feb 13, 2012, at 15:45, email@hidden wrote:
I have a script that controls Phlink and I've set a variable for "banned" phone numbers, like so:
...
However, I'd like to put them in a text file for ease of entry, like so:
______________________________________________________________________

Hey Marc,

I was off the air for a couple of days and am just catching up.

I frequently do this sort of thing, so here are four more methods to add to the list.

set bannedListAlias to alias "Thor:Users:chris:Desktop:Banned_List.txt"

----------------------------------------------------------------------------------------------

# Using 'read with delimiter':

set bannedList to read bannedListAlias using delimiter linefeed
# Purge any empty list items:
set tempList to {}
if bannedList contains "" then
repeat with i in bannedList
set _temp to contents of i
if _temp ≠ "" then
set end of tempList to _temp
end if
end repeat
set {bannedList, tempList} to {tempList, ""}
end if

bannedList

----------------------------------------------------------------------------------------------

# Using the 'grep' command-line tool:

set cmd to "egrep ^[0-9]+ " & quoted form of POSIX path of bannedListAlias
set bannedList to paragraphs of (do shell script cmd)

----------------------------------------------------------------------------------------------

# Using the 'sed' command-line tool:

set cmd to "sed -nE /^[0-9]+/p " & quoted form of POSIX path of bannedListAlias
set bannedList to paragraphs of (do shell script cmd)

----------------------------------------------------------------------------------------------

# Using the Satimage.osax (My preferred method):

set bannedList to find text "^\\d+$" in bannedListAlias ¬
all occurrences true ¬
with regexp and string result

----------------------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
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

References: 
 >Populating a variable from a txt file (From: email@hidden)

  • Prev by Date: RE: INDESIGN: Text Inset
  • Next by Date: Gatekeeper
  • Previous by thread: Re: Populating a variable from a txt file
  • Next by thread: identify text based on paragraph style
  • Index(es):
    • Date
    • Thread