01.12.2012 17:43:00 • Categories: Applescript • Tags: Applescript
Test AppleScript
--example 1
set theFile to (choose file with prompt "Select a file to read:" of type {"TEXT"})
open for access theFile
set fileContents to (read theFile)
close access theFile
--example 2
on readFile( unixPath )
set foo to (open for access (POSIX file unixPath ))
set txt to (read foo for (get eof foo))
close access foo
return txt
end readFile
--example 3 UTF-16
on readFile( unixPath )
set foo to (open for access (POSIX file unixPath ))
set txt to (read foo for (get eof foo) as Unicode text)
close access foo
return txt
end readFile
--example 4 UTF-8
on readFile( unixPath )
set foo to (open for access (POSIX file unixPath ))
set txt to (read foo for (get eof foo) as «class utf8»)
close access foo
return txt
end readFile
--example 5 with terminal
on readFile( unixPath )
return (do shell script "cat '" & unixPath & "'")
end