Recently I made a script that put whatever I am watching in Mplayer into Adium’s status message field. I run it every minute through launchd but when it checks every minute the status message blinks since it is putting whatever output it finds regardless of the title being the same.
It seems to be an issue with libpurple but I thought I could get around it by put a few lines after the one that outputs the result.
Here is part of what I have:
tell process result to get name of window 1
if exists process "Adium" then tell application "Adium" to set status message of account "account_email_here" to result
I then tried to add a statement:
tell process result to get name of window 1
if exists process "Adium" then tell application "Adium"
if status message of account "account_email_here" equals result then
end if
if status message of account "account_email_here" does not equal result then
set status message of account "account_email_here" to result
But I get something along the lines of "Expected “else”, etc. but found “end tell”.
two suggestions:
For better readability don’t use an application tell block in the same line as an if statement.
the internal variable result contains always the result of the last executed line.
It’s better to define a variable, e.g.
set windowName to name of window 1 of process result
if exists process "Adium" then
tell application "Adium"
set status message of account "account_email_here" to windowName
end tell
end if
Alright I cleaned tell and if lines up a bit and tried the single if statement but no luck
tell application "System Events"
get name of some process whose name contains "MPlayer OSX Extended"
tell process result to get name of window 1
if exists process "Adium" then
tell application "Adium"
if result does not equal status message then
set status message of account "email_goes_here" to result
end if
end tell
I’m not sure on how to properly define a variable for ‘result’ and I still get the syntax error that expects ‘else’
, the processes’ name whose name contains the very processes’ name for which you are looking is itself. That line is superfluous.
You received the error expecting “else” because your if considerations aren’t properly closed. With rare exception, commands broken across multiple lines must terminate with an “end” statement. If the line contains an unbroken tell (tell something to) or if (inclusive of then), there’s an implied terminus.
I have neither of these apps, but I believe something along these lines will work. The try block ignores any nonexistent processes or windows.
tell application "System Events" to try
set stsmsg to (process "MPlayer OSX Extended")'s item 1's window 1's name
tell process "Adium" to if status message ≠stsmsg then set status message to stsmsg
end try
status message is a part of Adium’s dictionary, so you need an tell application “Adium” statement.
try
tell application "System Events"
set stsmsg to (process "MPlayer OSX Extended")'s item 1's window 1's name
end tell
tell application "Adium"
if status message ≠stsmsg then set status message to stsmsg
end tell
on error e
display dialog "an error occured:" & return & e
end try