Select Page

This article cross-posted from here

—–

Open the AppleScript Editor on your Mac, then paste the following script in to a new file:

property theUsername : "your username"
property thePassword : "your password"
property theURL : "https://www.xpenser.com/api/v1.0/expense/"
property theQueryTimeout : 10
property theDefaultQuery : "Lunch 12.14 ModMarket with Marcus #clientX"

on postExpense(theQuery)
    set XpenserUpdate to "/usr/bin/curl -s -S -m " & theQueryTimeout & ¬
        " -u " & quoted form of (theUsername & ":" & thePassword) & ¬
        " -d " & quoted form of ("q=" & theQuery) & ¬
        " " & quoted form of theURL
    set XpenserResponse to do shell script XpenserUpdate
    if XpenserResponse contains ""status": 1" then
        return "Your expense was saved."
    else
        return "There was a problem saving your expense!"
    end if
end postExpense

set theResult to display dialog "Add A New Expense" default answer theDefaultQuery

set theQuery to text returned of theResult
set theButton to button returned of theResult
if theButton is equal to "OK" and theQuery is not equal to theDefaultQuery then
    set theResponse to postExpense(theQuery)
    say theResponse
else
    -- do nothing
end if

Then update your username and password and save as an application in your applications folder (I called it SendToXpenser).

SendToXpenser-AppleScript-Editor.png

Now you can type apple-space to open Spotlight type SendToXpenser and press return.

SendToXpenser-Spotlight.png

You are prompted for quick entry text and you get voice confirmation if the expense was added or not.

SendToXpenser-1.png

If you want to launch this directly with a keyboard shortcut, you can create a service with Automator. Specify no input and use the run applescript action to run the above script (remember to update your username and password.) Then in System Preferences -> Keyboard you can assign a keyboard shortcut to this service.

Pin It on Pinterest

Sharing is caring

Share this post with your friends!