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

1#!/bin/bash
2loggedInUser=$(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 + "
3");')
4Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)
5
6#if that result is blank then
7 if [ -z "$Echoing" ]; then
8 echo "<result>No Echoing</result>"
9 else
10#if its not blank print the result
11 echo "<result>$Echoing</result>"
12 fi
13exit 0
1#!/bin/bash
2loggedInUser=$(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 + "
3");')
4echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
5
6
7#if that result is blank then
8 if [ -z "$echoDays" ]; then
9 echo "<result>No echoDays</result>"
10 else
11#if its not blank print the result
12 echo "<result>$echoDays</result>"
13 fi
14exit 0
1#!/bin/bash
2loggedInUser=$(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 + "
3");')
4Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)
5
6#if that result is blank then
7 if [ -z "$Echoing" ]; then
8 echoing_Result="no Echoing"
9 else
10#if its not blank print the result
11 echoing_Result=$Echoing
12 fi
13
14echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
15#if that result is blank then
16 if [ -z "$echoDays" ]; then
17 echoDays_Result="no echoDays"
18 else
19#if its not blank print the result
20 echoDays_Result=$echoDays
21 fi
22
23
24echo "<result> $echoing_Result & $echoDays_Result </result>"
25exit 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

1#!/bin/bash
2loggedInUser=$(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 + "
3");')
4Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)
5
6#if that result is blank then
7 if [ -z "$Echoing" ]; then
8 echo "<result>No Echoing</result>"
9 else
10#if its not blank print the result
11 echo "<result>$Echoing</result>"
12 fi
13exit 0
1#!/bin/bash
2loggedInUser=$(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 + "
3");')
4echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
5
6
7#if that result is blank then
8 if [ -z "$echoDays" ]; then
9 echo "<result>No echoDays</result>"
10 else
11#if its not blank print the result
12 echo "<result>$echoDays</result>"
13 fi
14exit 0
1#!/bin/bash
2loggedInUser=$(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 + "
3");')
4Echoing=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoing)
5
6#if that result is blank then
7 if [ -z "$Echoing" ]; then
8 echoing_Result="no Echoing"
9 else
10#if its not blank print the result
11 echoing_Result=$Echoing
12 fi
13
14echoDays=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
15#if that result is blank then
16 if [ -z "$echoDays" ]; then
17 echoDays_Result="no echoDays"
18 else
19#if its not blank print the result
20 echoDays_Result=$echoDays
21 fi
22
23
24echo "<result> $echoing_Result & $echoDays_Result </result>"
25exit 0

boberito
Forum|alt.badge.img+22
  • Jamf Heroes
  • 451 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!


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 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.

1#!/bin/bash
2
3loggedInUser=$(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 + "
4");')
5
6if [ -e "/Users/$loggedInUser/Library/Preferences/com.dms.echo.plist" ]; then
7 echoDaysVal=$(defaults read /Users/$loggedInUser/Library/Preferences/com.dms.echo.plist echoDays)
8 echoingVal=$(defaults read /Users/$loggedInUser/Desktop/com.dms.echo.plist echoing)
9
10 results=("echoDays: ${echoDaysVal}" "echoing: ${echoingVal}")
11
12 echo "<result>$(printf '%s
13' "${results[@]}")</result>"
14else
15 echo "<result>No results</result>"
16fi

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