Skip to content

Commit

Permalink
SlackStatus: Add expiry param (#3)
Browse files Browse the repository at this point in the history
* SlackStatus: Add expiry param

* Update readme
  • Loading branch information
mirka authored Feb 20, 2021
1 parent 6cdda5a commit 92c0705
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Binary file modified assets/set-slack-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/set-slack-status/Keyboard Maestro Action.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<key>Default</key>
<string>In a meeting</string>
</dict>
<dict>
<key>Label</key>
<string>Clear after x hours</string>
<key>Type</key>
<string>Calculation</string>
</dict>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions src/set-slack-status/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ You will first need a Slack OAuth access token with the `users.profile:write` sc
- **OAuth token**: Paste your OAuth token here.
- **Status emoji**: An emoji identifier enclosed by colons, e.g. `:palm_tree:`. All the custom emoji for your workspace are also available.
- **Status text**: Your status message.
- **Clear after x hours**: Optional status expiration (in hours). This field supports [calculations](https://wiki.keyboardmaestro.com/manual/Calculations), so you can do things like `5*24` for your status to clear after 5 days, or `15/60` to clear after 15 minutes.

The action will return the JSON response from the Slack server. If you save this to a variable, for example called `result`, you can easily parse this by using text tokens like `%JSONValue%result.profile%`.
13 changes: 13 additions & 0 deletions src/set-slack-status/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ if [[ ! -z "$KMPARAM_Status_text" || $both_empty -eq 0 ]]; then
params+=("$text_param")
fi

# Calculate expiration unixtime (if set to more than 0)
if [[ $(bc -l <<< "$KMPARAM_Clear_after_x_hours > 0") -eq 1 ]]; then
unix_now=$(date +%s)
offset=$(bc -l <<< "$KMPARAM_Clear_after_x_hours * 3600")
integer_offset=$(printf "%.0f" $offset)
expiry=$(($unix_now + $integer_offset))
else
expiry=0
fi

expiration_param="\"status_expiration\": $expiry"
params+=("$expiration_param")

# Join params with ',' delimiter
for p in "${params[@]}"; do
if [[ ! -z "$concated_params" ]]; then
Expand Down

0 comments on commit 92c0705

Please sign in to comment.