Several AS; help needed. will buy BEER!!! #2 Matrix Parser

Posted on
Tue Oct 29, 2019 8:11 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Several AS; help needed. will buy BEER!!! #2 Matrix Parser

this one is a parser for my Vaux Audio matrix switch.

Code: Select all
using terms from application "IndigoServer"
   tell application "IndigoServer"
      
      if value of variable "vauxResponse" contains "!s" then
         
         set vauxResponseString to value of variable "vauxResponse"
         if value of variable "vauxLogging_Enabled" is equal to "true" then
            log vauxResponseString
         end if
         set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}
         set myList to text items of vauxResponseString
         
         set AppleScript's text item delimiters to myTID -- It's considered good practice to return the TID's to their original state
         --log list of myList
         --if myList contains less than 5 items then
         stop
      end if
      
      
      try
         if item 2 of myList is "40" then --this is for setting bass and treble.
            set vauxZoneNumber to item 3 of myList
            
            
            set vauxBassSetting to item 4 of myList
            
            set vauxTrebleSetting to item 5 of myList as string
            
            
            log ((vauxZoneNumber as string) & "  " & (vauxBassSetting as string) & "  " & (vauxTrebleSetting as string))
            
            
            if vauxZoneNumber is "0" then set value of variable "vauxZoneName" to "Off" as text
            if vauxZoneNumber is "1" then set value of variable "vauxZoneName" to "Kitchen" as text
            if vauxZoneNumber is "2" then set value of variable "vauxZoneName" to "FamRm" as text
            if vauxZoneNumber is "3" then set value of variable "vauxZoneName" to "Study" as text
            
            if vauxZoneNumber is "4" then set value of variable "vauxZoneName" to "LivDnRm" as text
            if vauxZoneNumber is "5" then set value of variable "vauxZoneName" to "GameRm" as text
            if vauxZoneNumber is "6" then set value of variable "vauxZoneName" to "Patio" as text
            if vauxZoneNumber is "7" then set value of variable "vauxZoneName" to "Pool" as text
            if vauxZoneNumber is "8" then set value of variable "vauxZoneName" to "MBR" as text
            
            
            set value of variable "vauxResponseBassTreble" to ((value of variable "vauxZoneName" as string) & "  Bass " & (vauxBassSetting as string) & "  Treble " & (vauxTrebleSetting as string))
            
            
            log value of variable "vauxResponseBassTreble" as string
            
         end if
         
      end try
      
      try
         
         if item 2 of myList is "1" then --this is the standard response. Don't log
            set vauxZoneNumber to item 3 of myList
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxZoneNumber --as string
            end if
            set vauxSourceNumber to item 5 of myList
            
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxSourceNumber
            end if
            set vauxVolumeLevel to item 6 of myList as string
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxVolumeLevel
            end if
         end if
         
         
         if item 2 of myList is "3" then
            
            set vauxZoneNumber to item 3 of myList
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxZoneNumber --as string
            end if
            
            set vauxSourceNumber to item 5 of myList
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxSourceNumber
            end if
            
            set vauxVolumeLevel to item 6 of myList --as string
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxVolumeLevel
            end if
            
         end if
         
         if item 2 of myList is "20" then
            set vauxZoneNumber to item 3 of myList
            
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxZoneNumber --as string
               --set vauxSourceNumber to item 4 of myList
               log vauxSourceNumber
            end if
            
            set vauxVolumeLevel to item 5 of myList --as string
            if value of variable "vauxLogging_Enabled" is equal to "true" then
               log vauxVolumeLevel
            end if
            
         end if
         
         
         
         if vauxZoneNumber is "0" then set value of variable "vauxZoneName" to "Off " as text
         if vauxZoneNumber is "1" then set value of variable "vauxZoneName" to "Kitchen(K)" as text
         if vauxZoneNumber is "2" then set value of variable "vauxZoneName" to "Kitchen(F)" as text
         if vauxZoneNumber is "3" then set value of variable "vauxZoneName" to "Kitchen(S)" as text
         
         if vauxZoneNumber is "4" then set value of variable "vauxZoneName" to "LivDnRm" as text
         if vauxZoneNumber is "5" then set value of variable "vauxZoneName" to "GameRm" as text
         if vauxZoneNumber is "6" then set value of variable "vauxZoneName" to "Patio" as text
         if vauxZoneNumber is "7" then set value of variable "vauxZoneName" to "Pool" as text
         if vauxZoneNumber is "8" then set value of variable "vauxZoneName" to "MBR " as text
         
         if vauxSourceNumber is "0" then set value of variable "vauxSourceName" to "Off " as text
         if vauxSourceNumber is "1" then set value of variable "vauxSourceName" to "Tuner" as text
         if vauxSourceNumber is "2" then set value of variable "vauxSourceName" to "iTunesPan" as text
         if vauxSourceNumber is "3" then set value of variable "vauxSourceName" to "AirPlay" as text
         if vauxSourceNumber is "4" then set value of variable "vauxSourceName" to "Cable" as text
         --if vauxSourceNumber is "5" then set value of variable "vauxSourceName" to "Cable" as text
         if vauxSourceNumber is "8" then set value of variable "vauxSourceName" to "Tone Levels" as text
         
         set value of variable "vauxZoneVolume" to vauxVolumeLevel
         
         
         set value of variable "vauxResponseCombinedOutput" to ((value of variable "vauxZoneName" as string) & "  " & (value of variable "vauxSourceName" as string) & "  " & (value of variable "vauxZoneVolume" as string))
         
         --if value of variable "vauxLogging_Enabled" is equal to "true" then
         log value of variable "vauxResponseCombinedOutput" as string
         --end if
         
      end try
      
      --the short zone name is used on the opening control page to see what's happening at a glance
      set vauxShortZone to value of variable "vauxZoneName" as string
      set vauxShortZoneName to (characters 1 through 4 of vauxShortZone) as string
      
      set value of variable "vauxResponseOutputShort" to ((characters 1 through 4 of vauxShortZoneName as string) & " " & (characters 1 through 4 of (value of variable "vauxSourceName" as string)) & " " & (value of variable "vauxZoneVolume" as string)) as string
      if value of variable "vauxLogging_Enabled" is equal to "true" then
         log value of variable "vauxResponseOutputShort" as string
      end if
      
      
      if item 2 of myList is "91" then
         set value of variable "vauxResponseOutputShort" to "Now Paging"
         log "Now Paging"
         
         set value of variable "vauxResponseCombinedOutput" to "Now Paging"
         
      end if
      
      if item 2 of myList is "90" then
         set value of variable "vauxResponseOutputShort" to "Paging Stopped"
         log "Paging Stopped"
         
         set value of variable "vauxResponseCombinedOutput" to "Paging Stopped"
         
      end if
      
   end tell
end using terms from


Posted on
Wed Oct 30, 2019 10:42 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Several AS; help needed. will buy BEER!!! #2 Matrix Par

This script has several logical fallacies which will likely cause it to fail. I assume it's why you have most everything wrapped in try blocks. But it may also lead to misleading results in that the parts not in the try block may execute when they actually really shouldn't.

My recommendation is that you describe all the possible strings that the Indigo variable "vauxResponse" can have, and what you want to happen for each of them. Not as code, but rather just a description. I suspect this script can be much simpler if we just start from scratch with what you want rather than what the current script does.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Oct 30, 2019 12:09 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Re: Several AS; help needed. will buy BEER!!! #2 Matrix Par

Hi Jay,

Thanks for the note. I adapted the parser example I had found on the web. It works flawlessly, despite the apparent issues. I'll try to boil it down when I get some time. Can't move on to 7.4 without fixing these scripts and I just don't have the time to do the research myself. Hence my offer of payment to anyone that will help expedite the process.

Ham

Posted on
Wed Oct 30, 2019 12:24 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Several AS; help needed. will buy BEER!!! #2 Matrix Par

Jay

Some ref here:


viewtopic.php?f=252&t=21331#p166848


Sent from my iPhone using Tapatalk Pro

Posted on
Wed Oct 30, 2019 1:06 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Several AS; help needed. will buy BEER!!! #2 Matrix Par

howartp wrote:
Jay

Some ref here:


viewtopic.php?f=252&t=21331#p166848


Sent from my iPhone using Tapatalk Pro


@Ham - looks like we helped you with some of these conversions a year ago... :roll:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Oct 30, 2019 2:18 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Re: Several AS; help needed. will buy BEER!!! #2 Matrix Par

No problem with that. Looking to pay someone to help me get it done. Just don't have the time. Hope that is OK.

Ham

Posted on
Wed Oct 30, 2019 2:41 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Several AS; help needed. will buy BEER!!! #2 Matrix Par

Ah - if you want to pay someone for the conversion, I recommend posting to this forum instead (I've moved them for you). The
Help Converting from AppleScript forum is for people who want help in learning how to convert their scripts (and by extension learning Python and Indigo), not wholesale doing the work for you

If you'd like to create a single post in the Help Converting sub-forum (for visibility) that points to all of these requests that would be fine.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests