Explore these script examples to see how easy it is to control your DeskThang using simple commands and scripts. For a full list of available commands, check out our Commands page.
Change LED color based on Vim mode
#!/bin/bash
# Function to update DeskThang LED based on Vim mode
update_led() {
case $1 in
"normal")
deskthang led 00ff00 # Green for normal mode
;;
"insert")
deskthang led ff0000 # Red for insert mode
;;
"visual")
deskthang led 0000ff # Blue for visual mode
;;
esac
}
# Monitor Vim mode changes
vim -c "call ch_logfile('vim_mode.log', 'w')"
tail -f vim_mode.log | while read line
do
mode=$(echo $line | awk '{print $NF}')
update_led $mode
done
Change LED color based on CI/CD pipeline status
#!/bin/bash
# Function to check CI/CD status and update LED
check_cicd_status() {
status=$(curl -s https://api.your-ci-service.com/status)
if [ "$status" == "success" ]; then
deskthang led 00ff00 # Green for success
elif [ "$status" == "failure" ]; then
deskthang led ff0000 # Red for failure
else
deskthang led ffff00 # Yellow for in progress or unknown
fi
}
# Run the check every 5 minutes
while true
do
check_cicd_status
sleep 300
done
Use Stripe webhooks to trigger DeskThang notifications
from flask import Flask, request, jsonify
import stripe
import subprocess
app = Flask(__name__)
# Set your Stripe API key
stripe.api_key = "your_stripe_api_key"
# Set your webhook secret
webhook_secret = "your_webhook_secret"
def run_deskthang_command(command):
subprocess.run(["deskthang"] + command.split())
@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.data
sig_header = request.headers.get('Stripe-Signature')
try:
event = stripe.Webhook.construct_event(
payload, sig_header, webhook_secret
)
except ValueError as e:
return 'Invalid payload', 400
except stripe.error.SignatureVerificationError as e:
return 'Invalid signature', 400
if event['type'] == 'payment_intent.succeeded':
payment_intent = event['data']['object']
amount = payment_intent['amount'] / 100 # Convert cents to dollars
# Set DeskThang LED to green
run_deskthang_command("led 00ff00")
# Display notification on DeskThang
run_deskthang_command("notify 'New payment: $" + str(amount) + "'")
# Optional: Pulse the LED
run_deskthang_command("pulse 3")
elif event['type'] == 'payment_intent.payment_failed':
# Set DeskThang LED to red
run_deskthang_command("led ff0000")
# Display notification on DeskThang
run_deskthang_command("notify 'Payment failed'")
return jsonify(success=True)
if __name__ == '__main__':
app.run(port=5000)