Apple script-How to assign a variable from reading a file content and to send a message? This is a apple script as below. I want to read a file content and assign it as a variable for sending as iMessage content. But, I get an error. 

tell application "Messages"
    set targetBuddy to "+xxxxxxxxxxx"
    set targetService to id of 1st service whose service type = iMessage
    set Shows to paragraphs of (read POSIX file "/Users/human/macairspace.txt")
    set textMessage to Shows
    set theBuddy to buddy targetBuddy of service id targetService
    send textMessage to theBuddy
end tell


It shows an error message. 

error "「Messages」Error：Can't make「file \"Macintosh HD:Users:human:macairspace.txt\"」as「file」。" number -1700 from file "Macintosh HD:Users:human:macairspace.txt" to file
One possible cause of that error is the POSIX pathname, "/Users/human/macairspace.txt" is not correct; however, that is not the only thing wrong with your code:

Without going into details about what else is wrong, let be show you an example of how I'd code it, and this works for me when I replace "+nnnnnnnnnnn" and "/path/to/file.txt" with valid values.

Example AppleScript code:

set targetBuddy to "+nnnnnnnnnnn"
set textMessage to (read POSIX file "/path/to/file.txt")

tell application "Messages"
    set targetService to id of 1st service whose service type = iMessage
    set theBuddy to buddy targetBuddy of service id targetService
    send textMessage to theBuddy
end tell




Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the used to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.