Jump to content

Paste directly in app (query in Sequel Pro)


Recommended Posts

Hi,

 

I want my workflow to open Sequel Pro and paste a SQL query directly in the query field (and, ideally, run it and export to CSV). 

 

As of now, it opens Sequel Pro and gets the query in the clipboard so that I only have to do CMD-V into Sequel Pro. However, I was wondering if there is a way to automate that last part - paste, run query, and export to CSV (all of which would run from inside Sequel Pro).

 

Is this possible?

 

EDIT: I've created the query in it's own SQL file so workflow now opens that file with Sequel Pro --> CMD-V part is solved. Still missing Run Query + Export as CSV

Edited by miguelccarvalho
Achieved partial solution
Link to comment

You can simulate ⌘V and ⌘R using AppleScript to paste and run the query:

 

tell application "Sequel Pro"

    activate

    tell application "System Events"

        keystroke "v" using command down

        -- wait 1/5th of a second for the paste to complete

        delay 0.2

        keystroke "r" using command down

    end tell

end tell

Link to comment

I wasn't able to replicate this and I think it is because Sequel Pro requires me to hit "Connect" before it starts. 

 

Re-formulating the problem, I need something that:

1) Activates Sequel Pro;

2) Hits "Enter" in the "Connect" button which shows upon opening the app;

3) Pastes the query;

4) Runs the query;

5) Exports to CSV

 

I added something to the script and it works :)

 

My keyword is now connected to a Run Script object which contains:

tell application "Sequel Pro"
    activate
    tell application "System Events"
            keystroke return
        keystroke "v" using command down
        -- wait 1/5th of a second for the paste to complete
        delay 0.2
        keystroke "r" using command down
    end tell
end tell

So I'm just missing the export to CSV part as I can't find the keystroke in Sequel Pro for 'Export to CSV'. How can I do that?

 

Thanks a lot!

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...