Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI interface #564

Closed
logix2 opened this issue Jun 20, 2019 · 5 comments
Closed

Add CLI interface #564

logix2 opened this issue Jun 20, 2019 · 5 comments
Assignees
Labels
enhancement A request for a feature or additional functionality needs testing A contribution that needs testing

Comments

@logix2
Copy link

logix2 commented Jun 20, 2019

Is there a way to send a file from the command line using GSConnect, similar to kdeconnect-cli? If not, would it be possible to implement it? That's useful if for example you want to integrate it into some command that you trigger from the KDE Connect Android app, which sends you a file back to the phone upon command completion.

@andyholmes andyholmes added the enhancement A request for a feature or additional functionality label Jun 22, 2019
@andyholmes
Copy link
Collaborator

Currently there's no way to do this (easily). You can technically invoke any GAction registered by a device using something like:

$ gapplication action org.gnome.Shell.Extensions.GSConnect device "('your_device_id', 'shareFile', true, <('/path/to/file.txt', false)>)"

Clearly this is super obvious to everyone and fun to do 😉

GSConnect is a lot more amenable to use over DBus at the moment. I can try to add a proper CLI interface, but it might be awhile. I don't have much free time and there are some upcoming breaking changes in the KDE Connect protocol, as well as a number of other unfinished projects.

andyholmes added a commit that referenced this issue Jun 22, 2019
To aid with scripting and process handling, run commands using a
GSubprocessLauncher with the following environment variables:

* GSCONNECT_DEVICE_ID: the device id
* GSCONNECT_DEVICE_NAME: the device name
* GSCONNECT_DEVICE_ICON: the device themed icon-name
* GSCONNECT_DEVICE_DBUS: the device's object path on DBus

We also watch subprocesses now and check return codes.

addresses #564
@andyholmes
Copy link
Collaborator

andyholmes commented Jun 23, 2019

EDIT: there seems to be some problem with command-line handling, I'll try and fix this when I figure out the problem.

EDIT 2: okay, second zip should be good 🤞

Okay, so I guess I got bored and just did it 😕. Maybe you want to try this Zip and tell me what you think?

gsconnect@andyholmes.github.io.zip <-bad

gsconnect@andyholmes.github.io.zip <- good

If you want to run commands from the command-line you have enter the extension directory or call the full path of the script:

$ cd ~/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io
$ ./daemon.js --help
Usage:
  org.gnome.Shell.Extensions.GSConnect [OPTION…]

Help Options:
  -h, --help                    Show help options
  --help-all                    Show all help options
  --help-gapplication           Show GApplication options
  --help-gtk                    Show GTK+ Options

Application Options:
  -l, --list-devices            List all devices
  -a, --list-available          List available devices (connected and paired
  -d, --device=<device-id>      ID of a device to handle command
  -f, --file=<filepath|URI>     Share a local or remote file, by URI or absolute file path
  -n, --notification            Send a notification
  -c, --photo                   Take a photo with the device camera
  -p, --ping                    Ping the device
  -r, --ring                    Ring the device
  -s, --sms=<phone-number>      Send an SMS message
  -u, --url=<URL>               Send a URL
  -t, --title=<title>           Set the title for a notification
  -b, --body=<body>             Set the body for a notification, ping or SMS
  -i, --icon=<icon-name>        Set the icon name for a notification
  -v, --version                 Show release version
  --display=DISPLAY             X display to use

However, scripting from a command shared with a device is a little easier:

#!/bin/bash

echo $GSCONNECT;             # Path to the application (`daemon.js`)
echo $GSCONNECT_DEVICE_DBUS; # DBus object path, useful for Python, GJS or other script
echo $GSCONNECT_DEVICE_ID;
echo $GSCONNECT_DEVICE_NAME;
echo $GSCONNECT_DEVICE_ICON;

${GSCONNECT} --device ${GSCONNECT_DEVICE_ID} --file ${HOME}/test.jpg \
                                             --file ${HOME}/test.gif

Files and urls can be supplied more than once. The --body tag applies to a few commands, and you can run each command at least once in a single command. So this would work, it just might do more than you expect it to:

#!/bin/bash

${GSCONNECT} --device ${GSCONNECT_DEVICE_ID} \
             --file ${HOME}/test.jpg \
             --notification \
             --sms "555-5555" \
             --ping \
             --ring \
             --photo \
             --body "Gets sent as the notification, ping AND sms body" \
             --title "Notification Title" \
             --icon "dialog-information-symbolic" \
             --url "https://www.gnome.org/"

Have fun and let me know how it goes :)

@logix2
Copy link
Author

logix2 commented Jun 26, 2019

Sorry for answering so late, I was sick for the last few days. It's working great, thank you very much!

To anyone else reading this, note that the daemon.js file is in the service folder, and not in the root GSConnect folder. At least in the .zip attached above.

Another note that should make life easier in some cases. You can use something like ~/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js -d $(~/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js -a) to pass the device id for whatever device is currently available, even if it changes. It only works if only one device is available, but that should be the case for most.

@jcursiolf
Copy link

Hey @andyholmes , sorry to bother you by opening it again. I tried to use your 2nd zip and many commands work, some not. The ones that do not work with my OnePlus 5 (model A5000 with the altests stable Android/Oxigen OS 9.0.6) are --file, --sms, and --photo (the app has all permissions and the same functions do work normally through GUI or gapplication).

Semi-related: Just as a tip for anybody that wanted to use kdeconnect-cli to create a command to trigger a screenshot from the computer that is saved on the phone, this worked for me:

file=/tmp/$(hostname)_$(date "+%Y%m%d_%H%M%S").png; gnome-screenshot -f "${file}" && gapplication action org.gnome.Shell.Extensions.GSConnect device "('599c464b1328e364', 'shareFile', true, <('${file}', false)>)"

@andyholmes andyholmes added the needs testing A contribution that needs testing label Jul 4, 2019
@andyholmes andyholmes reopened this Jul 4, 2019
@andyholmes andyholmes changed the title Send file from command line (similar to kdeconnect-cli) Add CLI interface Aug 18, 2019
@andyholmes andyholmes self-assigned this Aug 18, 2019
@andyholmes andyholmes added this to the v25 milestone Aug 18, 2019
@andyholmes
Copy link
Collaborator

I'm marking this as closed, since the CLI interface is in v25. However, some of the options changed and might change again before v26. Hopefully I'll have a wiki page up by then documenting the whole thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A request for a feature or additional functionality needs testing A contribution that needs testing
Projects
None yet
Development

No branches or pull requests

3 participants