Yadle launches File Intelligence
and AI to Improve How We Work

Full width home advertisement

Post Page Advertisement [Top]



Extend the Yadle Desktop App with Custom Plug-ins

While searching with Yadle allows you to quickly find what it is you are looking for, being able to manipulate or perform custom actions on the results allows you to seamlessly integrate into your workflow. In this blog post, we’ll show you how to configure desktop app plug-ins and share a couple of examples.

One of the main capabilities the Yadle Desktop app provides compared to the web app, is the ability to Open files from your search results. This is only possible in the desktop app since it is able to access a user’s local filesystem. Of course, this means the Yadle user will need to have access to the underlying file returned in search results. The correct network mapping of how files are presented on user workstations will also need to be configured and should be done by your Yadle administrator.

Download and Install Yadle Desktop App
If you have not done so already, install the desktop app on your workstation. It is available for Linux, Windows, and MacOS. The desktop app is specific to your Yadle organization and can obtain appropriate download links from your Yadle admin.

Defining the Desktop Plug-in Dropdown Menu
In the following examples, the plug-ins will be installed and configured on a Linux CentOS 7 system. The same thing can be done on Windows and MacOS.

The first thing to do is create the following folders in your home directory.
$ mkdir -p ~/yadle/plugins
Next, create a plugins.json file which defines the items that will show on the dropdown menu. In this example I have defined 3 items:

~/yadle/plugins/plugins.json
[
   {
      "item": "Set Bucket Folder",
      "plugin": "set_bucket.json"
   },
   {
      "item": "Add to Bucket",
      "plugin": "bucket.json"
   },
   {
      "item": "Tag as Favorite",
      "plugin": "tag.json"
   }
]
Each defined item references a json file for each plugin.

Create JSON files for individual plug-ins.
Next, we will create the json files that describe the plugin and what code to run when triggered.

~/yadle/plugins/set_bucket.json
{
   "name": "Set Bucket Folder",
   "command": [
       "$HOME/yadle/plugins/set_bucket.sh"
   ],
   "enabled": true,
   "platforms": {
       "win32": false,
       "osx": false,
       "linux": true
   },
   "users": [
       "yadle"
   ]
}

~/yadle/plugins/bucket.json
{
   "name": “Add to Bucket",
   "command": [
       "$HOME/yadle/plugins/bucket.sh"
   ],
   "file_argument": "path",
   "enabled": true,
   "platforms":{
       "win32": false,
       "osx": false,
       "linux": true
   },
   "users":[
       "yadle"
   ]
}

~/yadle/plugins/tag.json
{
   "name": "Tag as Favorite",
   "command": [
       "$HOME/yadle/plugins/tag.sh"
   ],
   "file_argument": "id",
   "enabled": true,
   "platforms":{
       "win32": false,
       "osx": false,
       "linux": true
   },
   "users":[
       "yadle"
   ]
}

Create Scripts that will Execute when Plug-ins are Triggered
In each of the json files created above, a bash script is referenced that will be executed upon selecting the plug-in from the menu. Next, we will create the bash scripts for each plug-in item defined.

~/yadle/plugins/set_bucket.sh
#!/bin/bash

# this is the default bucket name
basebucket="${HOME}/Desktop/bucket_1"

# icon for notify-send messages
icon="${HOME}/yadle/plugins/logo.png"

# .../bucket1.data contains the full path of the current bucket.  If not,
# then put the default from above in the file.
if [ ! -f "${HOME}/yadle/plugins/bucket1.data" ]; then echo "${basebucket}">"${HOME}/yadle/plugins/bucket1.data"; fi

# get the bucket path from the file
bucket=$(< ~/yadle/plugins/bucket1.data)

# open file selector, start in current bucket
dir=$(zenity --file-selection --directory ${bucket})

# if selected dir does not exists, no change
if [ -z $dir ]; then
       notify-send -t 5000 -u normal -i ${icon} "Bucket is still '${bucket}'"
else
       # set selected dir to be the dir in bucket1.data file
       echo "${dir}">"${HOME}/yadle/plugins/bucket1.data"

       # desktop notify message
       notify-send -t 5000 -u normal -i ${icon} "Set bucket to '${dir}'"
fi

# EOF

~/yadle/plugins/bucket.sh
#!/bin/bash

# this is the default bucket name
basebucket="${HOME}/Desktop/bucket_1"

# icon for notify-send messages
icon="${HOME}/yadle/plugins/logo.png"

# full pathname from Yadle
fullpath=$1

# break filename into parts
filename="${fullpath##*/}"                      # Strip longest match of */ from start
dir="${fullpath:0:${#fullpath} - ${#filename}}" # Substring from 0 thru pos of filename
base="${filename%.[^.]*}"                       # Strip shortest match of . plus at least one non-dot char from end
ext="${filename:${#base} + 1}"

# .../bucket1.data contains the full path of the current bucket.  If not,
# then put the default from above in the file.
if [ ! -f "${HOME}/yadle/plugins/bucket1.data" ]; then echo "${basebucket}">"${HOME}/yadle/plugins/bucket1.data"; fi

# get the bucket path from the file
bucket=$(< ~/yadle/plugins/bucket1.data)

# if bucket does not exist, create it
if [ ! -f ${bucket} ]; then
       mkdir -p "${bucket}"
fi

# copy file to it
e=$(cp "${fullpath}""${bucket}")

# send desktop message
notify-send -t 5000 -u normal -i ${icon} "Copied '${base}.${ext}' to '${bucket}'"

# EOF

~/yadle/plugins/tag.sh  *Be sure to replace the values in <red> with your own.
#!/bin/bash

# Yadle username and password
username=<username>
password=<password>

# API server url
api_url="<API Server URL>"

# API app ID
app_id="<API App ID>"

# icon for notify-send messages
icon="${HOME}/yadle/plugins/logo.png"

# file id from Yadle
id=$1

auth=$(curl --silent \
--request POST \
--url ${api_url}/yadle/v2/auth/login \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'username='${username}'&password='${password})

prop="password"
temp=`echo ${auth} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
api_password=${temp##*|}

prop="token"
temp=`echo ${auth} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
token=${temp##*|}

curl -X PATCH \
--url "${api_url}/yadle/v2/file/${id}/tags" \
-H "Authorization: Bearer ${token}:${api_password}" \
-H "Content-Type: application/json" \
-H "x-app-id: ${app_id}" \
-d '{
"favorite": {
"action": "add"
    }
}'
# EOF

Relaunch Yadle Desktop App
If the desktop app is currently opened, you will need to exit and reopen it for the configured plugins to be loaded.

See The Plug-ins In Action

Set Bucket/Add To Bucket
First the destination folder (bucket) is set. Then we choose which files we want to add to the defined bucket.



Tag as Favorite
This plug-in utilizes the API to quickly tag files from search results as #favorite. The tags are applied by calling the Tag as Favorite plug-in. You can see only those which we have tagged by searching #favorite.


More Example Plug-ins on GitHub
Several example plug-ins along with complete details for configuration can be found on our GitHub.

These example plug-ins are written in both bash and python and can be used as a framework to create your own custom plug-ins. You can write the plug-ins in whatever programming language you want.

Head over to the Yadle Community to get help, ask questions, and share your plug-ins as well as ideas for new ones!

No comments:

Post a Comment

Bottom Ad [Post Page]


Join our Blog to discover new ideas, tips, cool use cases, and how to take advantage of Yadle to help you more easily and quickly find and use your files anywhere - in the Cloud and on devices