• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
UBports Robot Logo UBports Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Get/Set clipboard data from DBus or other background options in UT

Scheduled Pinned Locked Moved App Development
12 Posts 4 Posters 726 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tonton_
      last edited by tonton_ 22 May 2024, 23:25

      Hi for a project of mine, i would like to get the clipboard content (and set it) from a background service.

      I find the way of doing it on desktop through some dbus viewer, but i don't have this kind of tool on UT.

      I'm not familiar with dbus, but i like digging, and i would like to go through with this project of mine πŸ™‚

      Here is what i do on kde to get/set :
      get :

      dbus-send --print-reply --type=method_call --dest=org.kde.klipper /klipper org.kde.klipper.klipper.getClipboardContents
      

      set :

      dbus-send --type=method_call --dest=org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents string:"new_clipboard_example"
      

      On UT if found this method which looks interesting :

      destination=com.lomiri.content.dbus.Service serial=7946 path=/; interface=com.lomiri.content.dbus.Service; member=GetLatestPasteData
      

      and is triggered through a copy from the interface, but i didn't find a way to make the dbus call, or find the content, and i'm still looking for a set method...

      If anyone here have a clue, i'd be grateful ! thanks ! πŸ˜„

      L 1 Reply Last reply 23 May 2024, 07:25 Reply Quote 0
      • L Online
        lduboeuf @tonton_
        last edited by lduboeuf 23 May 2024, 07:25

        @tonton_ said in Get/Set clipboard data from DBus or other background options in UT:

        you can introspect the service by doing this:

        dbus-send --session --type=method_call --print-reply \ --dest=com.lomiri.content.dbus.Service \ / \ org.freedesktop.DBus.Introspectable.Introspect

        there is a method CreatePaste which seems to do the job, but looking at input arguments expected, it seems not easy to use
        <method name="CreatePaste">
        <arg direction="in" type="s" name="app_id"/>
        <arg direction="in" type="s" name="surfaceId"/>
        <arg direction="in" type="ay" name="mimeData"/>
        <arg direction="in" type="as" name="types"/>
        <arg direction="out" type="b" name="success"/>
        </method>

        L T 2 Replies Last reply 23 May 2024, 07:30 Reply Quote 1
        • L Online
          lduboeuf @lduboeuf
          last edited by 23 May 2024, 07:30

          Also dbus-monitor --session when doing a copy/paste from UI reveals the method called

          1 Reply Last reply Reply Quote 1
          • T Offline
            tonton_
            last edited by 23 May 2024, 07:41

            Oh yeah, thanks for these infos πŸ™‚ , i'll take a look after work ! Cheers

            1 Reply Last reply Reply Quote 0
            • T Offline
              tonton_ @lduboeuf
              last edited by 23 May 2024, 11:08

              @lduboeuf
              trying to use the introspectable method to build a call

              The methods :

              <interface name="com.lomiri.content.dbus.Service">
              <method name="GetLatestPasteData">
                    <arg direction="in" type="s" name="surfaceId"/>
                    <arg direction="out" type="ay" name="mimeData"/>
                  </method>
                  <method name="GetPasteData">
                    <arg direction="in" type="s" name="surfaceId"/>
                    <arg direction="in" type="s" name="pasteid"/>
                    <arg direction="out" type="ay" name="mimeData"/>
                  </method>
              

              The call attempt :

              phablet@ubuntu-phablet:~$ dbus-send --session --type=method_call --print-reply --dest=com.lomiri.content.dbus.Service / com.lomiri.content.dbus.Service.GetPasteData
              
              Error org.freedesktop.DBus.Error.UnknownMethod: No such method 'GetPasteData' in interface 'com.lomiri.content.dbus.Service' at object path '/' (signature '')
              

              I'm not sure what i'm doing wrong here, giving the method exists (introspectable). I didn't try to give args on purpose, just to try to build correctly the call first

              A 1 Reply Last reply 23 May 2024, 11:44 Reply Quote 0
              • A Offline
                arubislander @tonton_
                last edited by 23 May 2024, 11:44

                @tonton_ I think not providing any arguments is what is triggering the error. In effect it is saying, there does not exist any method with that name that takes no arguments.

                πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                Happily running Ubuntu Touch
                Google Pixel 3a (20.04 DEV)
                JingPad (24.04 preview)
                Meizu Pro 5 (16.04 DEV)

                T 1 Reply Last reply 23 May 2024, 13:12 Reply Quote 1
                • T Offline
                  tonton_ @arubislander
                  last edited by 23 May 2024, 13:12

                  @arubislander Thank you for the tip, you were right, i "just" have to find the proper way to encode/decode the "array of bytes" output from these dbus calls !

                  L 1 Reply Last reply 23 May 2024, 14:19 Reply Quote 0
                  • L Online
                    lduboeuf @tonton_
                    last edited by 23 May 2024, 14:19

                    @tonton_ said in Get/Set clipboard data from DBus or other background options in UT:

                    @arubislander Thank you for the tip, you were right, i "just" have to find the proper way to encode/decode the "array of bytes" output from these dbus calls !

                    I'm not sure if it is even doable as apparently it requires a "surface_id" and an "app_id" so this is something done for UI apps i guess

                    T 1 Reply Last reply 23 May 2024, 16:07 Reply Quote 0
                    • T Offline
                      tonton_ @lduboeuf
                      last edited by 23 May 2024, 16:07

                      @lduboeuf not sure either ^^ but if i can decode the bytes array, i believe i can at least retrieve the clipboard ! one step at a time here ! πŸ™‚

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tonton_
                        last edited by 24 May 2024, 13:45

                        so i get an array of bytes which looks like this :

                        03 00 00 00 34 00 00 00 0a 00 00 00 3e 00 00 00 09 00 00 00 47 00 00 00
                        

                        but longer.
                        It seems to be the clipboard content in mimedata, encoded, but i can't get how to decode it (tested through python or bash for now), sorry if dumb question, i'm getting more familiar with dbus, but not the most skilled around here, that's for sure πŸ™‚
                        Does anyone have some clue about this ? I tried some byte converters to try to identify the encoding, but didn't get through for now...

                        A 1 Reply Last reply 27 May 2024, 11:57 Reply Quote 0
                        • A Offline
                          AppLee @tonton_
                          last edited by AppLee 27 May 2024, 11:57

                          @tonton_

                          Do you know the content of the clipboard.
                          What I would do is copy a known string and try to guess if it's encoded and how.

                          I surmise your device is a 64bit ARM.
                          If I just try a simple ASCII conversion I get : "<LF>4><TAB>G"
                          So something like:

                          
                          4>    G
                          

                          Is it possible?

                          T 1 Reply Last reply 28 May 2024, 22:20 Reply Quote 1
                          • T Offline
                            tonton_ @AppLee
                            last edited by tonton_ 28 May 2024, 22:20

                            @AppLee
                            thanks for the tip, i tried with ascii converter, didn't think of that, it works πŸ™‚
                            I'll have to parse the resulting ascii (lots of escaped character, and html in it )

                            1 Reply Last reply Reply Quote 1
                            7 out of 12
                            • First post
                              7/12
                              Last post