Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

h1068

macrumors newbie
Original poster
Jun 10, 2012
12
0
Can I set the_user_list to read a text file of users separated by commas?

Code:
set the_user to do shell script "logname"
set the_user_list to 
if the_user is in the_user_list then
 
Last edited:
Absolutely you can!

Assuming you know where the text file with the list of users in it is located, this little helper function will allow you to format the returned raw data into an AppleScript list:

Code:
on text_to_list(txt, delim)
	set saveD to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {delim}
		set theList to every text item of txt
	on error errStr number errNum
		set AppleScript's text item delimiters to saveD
		error errStr number errNum
	end try
	set AppleScript's text item delimiters to saveD
	return (theList)
end text_to_list
To use this:
Code:
set the_user_list to my text_to_list(text_var, ",")
 
Try this :

Code:
set theFile to POSIX file "/Users/test/testtxt.txt"
set theUserList to words of (read theFile)
 

Attachments

  • Picture 5.png
    Picture 5.png
    66.5 KB · Views: 130
  • Picture 6.png
    Picture 6.png
    54.4 KB · Views: 165
Thank you, you just saved me from posting 500 users into my applescript!
 
@wrldwzrd89

Your handler is more robust if the usernames contain spaces. But that can be solved by putting every username on a new line in the txtfile and using this :

Code:
set theUserList to paragraphs of (read theFile)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.