This script runs in geektool and tells me not only what msgs are flagged but also which ones I flagged from my iP?p. It works and gives me the output I want. It just seems overly complicated and a bit slow for a simple task. Looking for suggestions to optimize the whole thing. I know I could have used may other tools but this is as much part of my learning applescript as it is something I really needed :-)
set target_account to "gmail"
set iosflag_mailbox to "[Google Mail]/Starred"
set target_mailbox to "INBOX"
set outputList to {}
set crlf to ASCII character 10
set colon to ": "
set iconExjim to "○ "
set theIcon to "● "
tell application "Mail"
set inboxMsgs to message id of every message in mailbox target_mailbox of account target_account whose flagged status is true
set iosMsgs to message id of every message in mailbox iosflag_mailbox of account target_account
repeat with n from 1 to count of iosMsgs
if item n of iosMsgs is in my inboxMsgs then
set theMsg to (every message of mailbox target_mailbox of account target_account whose message id is equal to my item n of iosMsgs)
set theMsg_id to item 1 of theMsg
set fromMsg to sender of theMsg_id
set subjMsg to subject of theMsg_id
if (count of subjMsg) is greater than 40 then
set subjMsg to characters 1 through 40 of subjMsg
end if
set end of outputList to {theIcon, (word 1 of fromMsg), space, (word 2 of fromMsg) & colon, subjMsg, crlf}
else
set theMsg to (every message of mailbox iosflag_mailbox of account target_account whose message id is equal to my item n of iosMsgs)
set theMsg_id to item 1 of theMsg
set fromMsg to sender of theMsg_id
set subjMsg to subject of theMsg_id
if (count of subjMsg) is greater than 40 then
set subjMsg to characters 1 through 40 of subjMsg
end if
set end of outputList to {iconExjim, (words 1 through 2 of fromMsg), colon, subjMsg, crlf}
end if
--outputList
set finalText to outputList as string
end repeat
end tell