No internet connection
  1. Home
  2. How to

Get Device Id of device that triggered the script

By samuel henriques @samuel_henriques
    2021-04-24 16:22:40.073Z

    Is there a way to get the device id of the device that triggered the script?

    I'm navigating surfaces on one iPad, and need the script to know, witch iPad is pressing the button.

    not sure if I'm being clear...

    Thank you

    Solved in post #2, click to view
    • 10 replies
    1. You can access the device object through event.surface.device

      Currently, you cannot get the device id through that mechanism, but you can use the device object as input to the sf.surfaces.get('...').open() action's device parameter.

      ReplySolution
      1. samuel henriques @samuel_henriques
          2021-04-24 17:04:31.776Z

          Cool that worked.

          Thank you so much.

          1. samuel henriques @samuel_henriques
              2021-05-04 12:36:59.602Z

              Hi Christian,

              this has been working pretty good, with a commands like this:

              sf.surfaces.get('user:ckdsx2kse0001rp10kif21fs8:ckkpz1im80000qx102tljvx6x').open({
                  device: event.surface.device,
                  openMode: "OpenOrCreate",
              });
              

              Now if/when I quit and re-open soundFlow, the devices go back to the soundFlow home, witch is fine. I even made script that will open the correct surface on all devices in one button.

              But If I only restart soundFlow the surfaces stay up, scripts work, but these buttons to open surfaces won't run, I need to go back to home, refresh and select again.
              I get this error: TypeError: Cannot read property 'device' of null
              Which leads me to believe he forgot the name of the surface.

              Is there a way I could either get the devices to go home when I restart and I call the surface. Or just make this work.

              Thank you so much.

              1. samuel henriques @samuel_henriques
                  2021-05-04 16:17:06.202Z

                  Another think I just found. If while the surface on the device is not working, If I open it on the computer, and press the same button, It works, opens the other surface on the device it was called from

                  1. samuel henriques @samuel_henriques
                      2021-05-07 15:17:56.190Z

                      Hello @chrscheuer,
                      Sorry to bother you about this again, any idea of what I could do to fix this.
                      Maybe I'm not so clear.

                      Thank you so much.

                    • Hi Samuel

                      If you get TypeError: Cannot read property 'device' of null it's because you're running the above script with a trigger or something not being run directly from a surface.
                      The event.surface.device will only work if the script is run by a button on an existing surface. So you can't reuse that same script and trigger it from somewhere else (for example an Application trigger), because in that case event.surface would be null.

                      You should instead make a macro using the action "Open Surface" and programmatically set the desired device, and assign a trigger to that.

                      You can learn how to do that here:

                      1. samuel henriques @samuel_henriques
                          2021-05-08 13:36:42.038Z

                          Hey Christian,

                          Thank you for your time. I'm not sure this is the case, the script works as intended if I quit and open soundFlow or if I refresh the devices on the app home.
                          Only when I restart soundFlow, do I get error.

                          here's a video:
                          https://we.tl/t-gDm22dnFPK
                          ( I keep missing the place I click because I was looking at the phone :) )

                          1. samuel henriques @samuel_henriques
                              2021-05-08 13:44:52.574Z

                              The reason I'm using event.surface.device is also, so the surface on my left is always A and on my right is B, doesn't matter witch device it is. It will work.

                              1. If this happens when you restart SF, then that sounds like the script has a trigger assigned that makes it run where event.surface is null (as I suggested).

                                Do you have triggers assigned to this command? You shouldn't.

                                1. samuel henriques @samuel_henriques
                                    2021-05-08 14:15:58.919Z

                                    No, no triggers:

                                    they all look like this.