Skip to main content
Solved

EA scripting query


Forum|alt.badge.img+12

Is an EA script able to output multiple lines of output? For instance, we want to display two attributes out of a plist file at /Users/loggedInUser/Library/Preferences/com.dms.echo.plist

The plist file looks like this...

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSNavPanelExpandedSizeForOpenMode</key> <string>{712, 448}</string> <key>NSStatusItem Preferred Position Item-0</key> <real>881</real> <key>echoDays</key> <integer>30</integer> <key>echoing</key> <true/> <key>dmsEchoHasBeenLaunched</key> <true/> <key>supportLogging</key> <true/> </dict> </plist>

We really only want the "echoDays" and "echoing" attributes displayed. Can a script format the output so those two attributes appear one line over the other?

Best answer by rderewianko

Okay, i took a stab at this
The first two are single result EA's the third combines them

#!/bin/bash
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)

#if that result is blank then
    if [ -z "$Echoing" ]; then
    echo "<result>No Echoing</result>"
    else 
#if its not blank print the result  
    echo "<result>$Echoing</result>"
    fi
exit 0
#!/bin/bash
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)


#if that result is blank then
    if [ -z "$echoDays" ]; then
    echo "<result>No echoDays</result>"
    else 
#if its not blank print the result  
    echo "<result>$echoDays</result>"
    fi
exit 0
#!/bin/bash
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)

#if that result is blank then
    if [ -z "$Echoing" ]; then
    echoing_Result="no Echoing"
    else 
#if its not blank print the result  
    echoing_Result=$Echoing
    fi

echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
#if that result is blank then
    if [ -z "$echoDays" ]; then
    echoDays_Result="no echoDays"
    else 
#if its not blank print the result  
    echoDays_Result=$echoDays
    fi


echo "<result> $echoing_Result & $echoDays_Result </result>"
exit 0
View original
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img+18
  • Honored Contributor
  • 486 replies
  • Answer
  • November 8, 2018

Okay, i took a stab at this
The first two are single result EA's the third combines them

#!/bin/bash
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)

#if that result is blank then
    if [ -z "$Echoing" ]; then
    echo "<result>No Echoing</result>"
    else 
#if its not blank print the result  
    echo "<result>$Echoing</result>"
    fi
exit 0
#!/bin/bash
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)


#if that result is blank then
    if [ -z "$echoDays" ]; then
    echo "<result>No echoDays</result>"
    else 
#if its not blank print the result  
    echo "<result>$echoDays</result>"
    fi
exit 0
#!/bin/bash
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)

#if that result is blank then
    if [ -z "$Echoing" ]; then
    echoing_Result="no Echoing"
    else 
#if its not blank print the result  
    echoing_Result=$Echoing
    fi

echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
#if that result is blank then
    if [ -z "$echoDays" ]; then
    echoDays_Result="no echoDays"
    else 
#if its not blank print the result  
    echoDays_Result=$echoDays
    fi


echo "<result> $echoing_Result & $echoDays_Result </result>"
exit 0

boberito
Forum|alt.badge.img+22
  • Jamf Heroes
  • 449 replies
  • November 8, 2018

Use printf it won't print a new line like echo.

So you could do

printf "<result>" then printf whatever you want, multiple values, multiple printfs. Then printf "</result>"

But the above solution works too.


Forum|alt.badge.img+12
  • Author
  • Contributor
  • 45 replies
  • November 9, 2018

Works great. Thanks guys!


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • November 9, 2018

I typically drop any items into a bash array in the script, and then use printf to print the array, splitting on line breaks.

#!/bin/bash

loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

if [ -e "/Users/$loggedInUser/Library/Preferences/com.dms.echo.plist" ]; then
     echoDaysVal=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
     echoingVal=$(defaults read /Users/$loggedInUser/Desktop/com.dms.echo.plist echoing)

     results=("echoDays: ${echoDaysVal}" "echoing: ${echoingVal}")

     echo "<result>$(printf '%s
' "${results[@]}")</result>"
else
     echo "<result>No results</result>"
fi

That will or should show 2 lines for the results. What you need to keep in mind is that not all areas of the Jamf UI are able to show multiple lines for EAs or other items, so your results here may vary. in some places it may show up as one line, not two. Jamf also has an odd track record of enabling, then breaking this functionality. Some versions may not display multiple lines and others might.


Forum|alt.badge.img+18
  • Honored Contributor
  • 486 replies
  • November 11, 2018

I've never used arrays but now you've got me interested @mm2270


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings