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

ohanian

macrumors newbie
Original poster
Apr 29, 2010
20
0
-- I have a question regarding applescript

-- I have a list of strings
set mylist to {"1", "2", "3", "4", "5"}
-- I want to convert to a list of integers

set myint to every item in mylist as integer

-- Try another way
set myint to every item as integer in mylist

--But both ways does not work
 
AppleScript doesn't really have facilities to manipulate lists as a whole like that - the usual approach is to step through the list, making your coercions as you go.

Code:
set mylist to {"1", "2", "3", "4", "5"}

repeat with x from 1 to (count mylist)
	try -- skip errors
		set item x of mylist to (item x of mylist as integer)
	end try
end repeat

mylist -->  {1, 2, 3, 4, 5}
 
thank you

Thank you,

Now my program works

Code:
-- Please note that home is a object in "Finder"
-- It does not work outside of tell application
tell application "Finder"
	activate
	set targetdirectory to folder "nobackup:zzz" of home
	-- Now obtain a list of all files in the directory
	set all_files_in_dir to every file in targetdirectory
	-- Next convert the file from class document to string
	repeat with x from 1 to (count all_files_in_dir)
		try -- skip errors
			set item x of all_files_in_dir to (item x of all_files_in_dir as string)
		end try
	end repeat
end tell
tell application "Preview" to open all_files_in_dir
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.