Last active
November 29, 2016 07:54
-
-
Save cbuck/3106283 to your computer and use it in GitHub Desktop.
Get buddies list from MESSAGES app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set newline to ASCII character 10 | |
set availableFormat to "\\033[0;37m" | |
set awayFormat to "\\033[0;30m" | |
set idleFormat to "\\033[0;30m" | |
set offlineFormat to "\\033[0;30m" | |
set unknownFormat to "\\033[0;30m" | |
set resetFormat to "\\033[0;30m" | |
set ownName to "****YOURNAME****" | |
set allBuddies to {} | |
set availableBuddies to {} | |
set awayBuddies to {} | |
set offlineBuddies to {} | |
set idleBuddies to {} | |
set unknownBuddies to {} | |
set availableBuddyNames to {} | |
set awayBuddyNames to {} | |
set offlineBuddyNames to {} | |
set idleBuddyNames to {} | |
set unknownBuddyNames to {} | |
set availableBuddyNamesCondensed to {} | |
set awayBuddyNamesCondensed to {} | |
set offlineBuddyNamesCondensed to {} | |
set idleBuddyNamesCondensed to {} | |
set unknownBuddyNamesCondensed to {} | |
set availableBuddiesString to "" | |
set awayBuddiesString to "" | |
set offlineBuddiesString to "" | |
set idleBuddiesString to "" | |
set unknownBuddiesString to "" | |
set availableBuddiesStringSorted to "" | |
set awayBuddiesStringSorted to "" | |
set offlineBuddiesStringSorted to "" | |
set idleBuddiesStringSorted to "" | |
set unknownBuddiesStringSorted to "" | |
set buddyListString to "" | |
if appIsRunning("Messages") then | |
tell application "Messages" | |
repeat with currentService in services | |
repeat with currentBuddy in every buddy of currentService | |
if full name of currentBuddy is not ownName then | |
copy currentBuddy to the end of allBuddies | |
end if | |
end repeat | |
end repeat | |
repeat with currentBuddy in allBuddies | |
if status of currentBuddy is offline then | |
copy currentBuddy to the end of offlineBuddies | |
end if | |
if status of currentBuddy is available then | |
copy currentBuddy to the end of availableBuddies | |
end if | |
if status of currentBuddy is away then | |
copy currentBuddy to the end of awayBuddies | |
end if | |
if status of currentBuddy is idle then | |
copy currentBuddy to the end of idleBuddies | |
end if | |
if status of currentBuddy is unknown then | |
copy currentBuddy to the end of unknownBuddies | |
end if | |
end repeat | |
repeat with buddyName in availableBuddies | |
set buddyNameString to do shell script "echo " & full name of buddyName & newline without altering line endings | |
set availableBuddiesString to availableBuddiesString & buddyNameString | |
end repeat | |
repeat with buddyName in awayBuddies | |
set buddyNameString to do shell script "echo " & full name of buddyName & newline without altering line endings | |
set awayBuddiesString to awayBuddiesString & buddyNameString | |
end repeat | |
repeat with buddyName in offlineBuddies | |
set buddyNameString to do shell script "echo " & full name of buddyName & newline without altering line endings | |
set offlineBuddiesString to offlineBuddiesString & buddyNameString | |
end repeat | |
repeat with buddyName in idleBuddies | |
set buddyNameString to do shell script "echo " & full name of buddyName & newline without altering line endings | |
set idleBuddiesString to idleBuddiesString & buddyNameString | |
end repeat | |
repeat with buddyName in unknownBuddies | |
set buddyNameString to do shell script "echo " & full name of buddyName & newline without altering line endings | |
set unknownBuddiesString to unknownBuddiesString & buddyNameString | |
end repeat | |
set offlineBuddiesStringSorted to do shell script "echo " & quoted form of offlineBuddiesString & " | sort -f" | |
set offlineBuddyNames to (paragraphs of offlineBuddiesStringSorted) | |
set availableBuddiesStringSorted to do shell script "echo " & quoted form of availableBuddiesString & " | sort -f" | |
set availableBuddyNames to (paragraphs of availableBuddiesStringSorted) | |
set awayBuddiesStringSorted to do shell script "echo " & quoted form of awayBuddiesString & " | sort -f" | |
set awayBuddyNames to (paragraphs of awayBuddiesStringSorted) | |
set idleBuddiesStringSorted to do shell script "echo " & quoted form of idleBuddiesString & " | sort -f" | |
set idleBuddyNames to (paragraphs of idleBuddiesStringSorted) | |
set unknownBuddiesStringSorted to do shell script "echo " & quoted form of unknownBuddiesString & " | sort -f" | |
set unknownBuddyNames to (paragraphs of unknownBuddiesStringSorted) | |
repeat with x from 2 to count of items of offlineBuddyNames | |
set n to item x of offlineBuddyNames | |
if n is not in offlineBuddyNamesCondensed then set end of offlineBuddyNamesCondensed to n | |
end repeat | |
repeat with x from 2 to count of items of unknownBuddyNames | |
set n to item x of unknownBuddyNames | |
if n is not in unknownBuddyNamesCondensed then set end of unknownBuddyNamesCondensed to n | |
end repeat | |
repeat with x from 2 to count of items of availableBuddyNames | |
set n to item x of availableBuddyNames | |
if n is not in availableBuddyNamesCondensed then set end of availableBuddyNamesCondensed to n | |
end repeat | |
repeat with x from 2 to count of items of awayBuddyNames | |
set n to item x of awayBuddyNames | |
if n is not in awayBuddyNamesCondensed then set end of awayBuddyNamesCondensed to n | |
end repeat | |
repeat with x from 2 to count of items of idleBuddyNames | |
set n to item x of idleBuddyNames | |
if n is not in idleBuddyNamesCondensed then set end of idleBuddyNamesCondensed to n | |
end repeat | |
set availableBuddiesString to "" | |
repeat with buddyName in availableBuddyNamesCondensed | |
set buddyNameString to do shell script "echo \"" & availableFormat & buddyName & resetFormat & "\"" & newline without altering line endings | |
set availableBuddiesString to availableBuddiesString & buddyNameString | |
end repeat | |
set awayBuddiesString to "" | |
repeat with buddyName in awayBuddyNamesCondensed | |
set buddyNameString to do shell script "echo \"" & awayFormat & buddyName & resetFormat & "\"" & newline without altering line endings | |
set awayBuddiesString to awayBuddiesString & buddyNameString | |
end repeat | |
set offlineBuddiesString to "" | |
repeat with buddyName in offlineBuddyNamesCondensed | |
set buddyNameString to do shell script "echo \"" & offlineFormat & buddyName & resetFormat & "\"" & newline without altering line endings | |
set offlineBuddiesString to offlineBuddiesString & buddyNameString | |
end repeat | |
set idleBuddiesString to "" | |
repeat with buddyName in idleBuddyNamesCondensed | |
set buddyNameString to do shell script "echo \"" & idleFormat & buddyName & resetFormat & "\"" & newline without altering line endings | |
set idleBuddiesString to idleBuddiesString & buddyNameString | |
end repeat | |
set unknownBuddiesString to "" | |
repeat with buddyName in unknownBuddyNamesCondensed | |
set buddyNameString to do shell script "echo \"" & unknownFormat & buddyName & resetFormat & "\"" & newline without altering line endings | |
set unknownBuddiesString to unknownBuddiesString & buddyNameString | |
end repeat | |
return availableBuddiesString & idleBuddiesString & awayBuddiesString | |
end tell | |
else | |
return "Messages not running" | |
end if | |
on appIsRunning(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end appIsRunning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment