prankousky
prankousky

Reputation: 81

Parse xml variables in applescript

I am trying to read this xml-file with applescript.

<?xml version="1.0" encoding="UTF-8"?>
    <user>
        <username>benutzer</username>
        <password>passwort</password>
        <ip>127.0.0.1</ip>
    </user>

    <vars>
        <display>15</display>
        <sleep>60</sleep>
        <volume>22</volume>
        <app1>"Plex Media Server"</app1>
    </vars>

The original applescript looks like this:

do shell script "pmset displaysleep 15" password "mypassword" with administrator privileges
do shell script "pmset sleep 60" password "mypassword" with administrator privileges
set volume output 20
tell application "Plex Media Server" 
    quit
end tell
say "Media off"

How can I insert the value of "display" tp "displayslep", the value of "app1" as the application to quit etc.?

I am using several applescripts and this would make it so much easier changing certain values without having to change each script on its own. Also, I am a beginner with not too much coding knowledge.

Thanks in advance :)

Upvotes: 0

Views: 585

Answers (1)

foo
foo

Reputation: 3259

In response to above comment, here's some example code:

tell application "System Events"
    set xmlDoc to make new XML data with properties {name:"note", text:"
    <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
    </note>"}
    get value of XML element "to" of XML element "note" of xmlDoc
end tell
--> "Tove"

Recommend investing in an AppleScript book - it's a huge pain to figure out this stuff without a guide.

(Obligatory: I co-wrote the Apress book.)

Upvotes: 1

Related Questions