Can't figure out how to read from plist
Hi All, I have a script to check if plist exists, if not it writes one. Then displays dialog and gets user input and writes username and email address to said plist value as string. That script rus this script that checks my IP, and if it's changed it sends an email. I had this working, but had the name and address written into the script. I am now trying to go further and pull those properties to the email fields from the plist.but I get an error saying "Can’t make "username" into type integer." Can some one please help me with this.
set the plistfile_path to path to desktop folder as string --(Seperate problem, I also can't figure out how to set path to "/Users/<user>/Library/Preferences")
set p_list to POSIX path of (plistfile_path & "example.plist")
set theName to value of item "username" of p_list --This line and the next line is where I'm having problems
set theAddress to value of item "emailaddress" of p_list
try
--See what the Current IpAddress is
set Current_ipAddress to do shell script "/usr/bin/curl http://checkip.dyndns.org | /usr/bin/awk '/: / {print $6}' | /usr/bin/cut -f 1 -d '<' "
--set Current_ipAddress to "192.168.1.256" as text --FOR TESTING PURPOSE ONLY
set ipAddress to Current_ipAddress
--See what the Old IPAddress is in the "ScriptCheckIPAddress.Plist file"
-- ScriptCheckIPAddress is the name of the variable
-- ipAddress is the value as text
set Old_IPAddress to (do shell script "defaults read ScriptCheckIPAddress ipAddress")
if Old_IPAddress = Current_ipAddress then
-- Don't do anything because nothing changed.
else
do shell script ("defaults write ScriptCheckIPAddress ipAddress " & ipAddress as text)
--If IPAddress is changed then send an Email
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:"Your IP Address has changed", content:"Your Current IPAddress is: " & Current_ipAddress}
tell newMessage
makenewto recipientat end of to recipientswith properties {name:theName, address:theAddress} --This is where I'm trying to use them
end tell
sendnewMessage
end tell
end if
on error --> no such file yet so write it to plist file
do shell script ("defaults write ScriptCheckIPAddress ipAddress " & ipAddress as text)
end try
iMac, Mac OS X (10.7.3), new 21" I5 Imac