set theFilePath to POSIX path of (choose file without invisibles)
set content of text field "fileToImport" of tab view item "importData-Tab" of tab view "tabView" of window "mainWindow" to theFilePath
How do I read from a POSIX file Path?
set filePath to contents of text field "fileToImport" as string
set fileID to open for access filePath
set fileData to read fileID as string
AppleScript’s “read” doesn’t like it. I get an “End of file error. (-39)” error.
Be careful how you use that term. To convert from a POSIX path to a Mac-style file object, you use POSIX file.
Try something like this:
set filePath to contents of text field "fileToImport" as string
set fileID to open for access (POSIX file filePath)
set fileData to read fileID as string
tell current tab view item of tab view "tabView" of window "mainWindow"
if name is "importData-Tab" then
set filePath to contents of text field "fileToImport" as string
set fileID to open for access (POSIX file filePath)
set fileData to read fileID as string
close fileID
display dialog fileData
else if name is "imageURL-Tab" then [...]
error: Can’t make «class psxf» “/Users/michael_ewald/Desktop/hello.txt” of «class cTVI» of «class tabV» “tabView” of window “mainWindow” into type file specification. (-1700)
set filePath to contents of text field "fileToImport" as string
set fileID to open for access (POSIX file filePath) as alias
set fileData to read fileID as string