Is it possible to make all .csv files open in Google Sheets by default?

I’m trying to phase out Excel and only use Google Sheets. So, when I download a .csv, rather than having to go through the multiple steps of opening Google Sheets in Chrome and then importing the file, I’d rather it just open in Google Sheets by default.

AFAIK, there’s no straightforward way to do this.

In “file info”, the “open with” menu demands the user select an app. Chrome is an app or course, but I want the .csv opened to a specific URL with a specific set of menu items and actions the webpage provides (i.e., “Open > Import…”, “Upload” menu tab, “Select a file from your device”, select the .csv).

I noodled around in Automator to create an Application that would do this but I don’t think it permits a chain of commands specific to menu items in a webpage. Same goes for an Apple Script. Maybe a Shell Script would do it, but I do not know since I’ve never made a Shell Script before.

Am I making this too complicated? Can anyone point me in the right direction?

Do you have Keyboard Maestro? That could automate the key presses for you.

Google Sheets is web a service, not a local standalone app, so you can’t really think or it and treat it like one.

Alternatively, if you use Google Drive, maybe you could just sync it and the n just interact with it directly through Drive on the web.

1 Like

Closest I am aware of is the Choosy app but it doesn’t look like it would be able to handle this. Perhaps the developer might be interested in adding a solution?

Similar app LinCastor seems to be a bit more configurable, but I have never used it. Website for the app says it can be set up to make files open with specific apps, so seems like what you are seeking might be able to be added if not currently possible.

Both seem to be limited to just browser choice, not url for opening the file.

1 Like

LinCastor includes AppleScript support - so worst case it ought to be possible to do what you wish in that way.

1 Like

Oh. I would love this too. It should be possible. With python you can create new sheets with google api (see gspread) so you might be able to create a python script that you could use as default application. When it runs it creates a new sheet and then opens the link to it in the browser. That is at least how I would do it.

1 Like

So I got someting working. I use keyboard maestro:

The code isn’t pretty but hey it works. I think there is room for some error handling (got some errors when opening a csv with some unsual chars).

# Change this to your python path
#!/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9

import os
import gspread
import sys
from pydrive.auth import ServiceAccountCredentials
from pydrive.auth import GoogleAuth

# Fill in your email
username = 'hello@youremail.com'

#Fill in path to client secret file
credentialspath = '/Users/username/client_secret.json'

csvpath = os.environ['KMVAR_Temporary']
content = open(csvpath, 'r', encoding="utf8").read()

gauth = GoogleAuth()
scope = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/spreadsheets']

gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name(credentialspath, scope)
gc = gspread.authorize(gauth.credentials)

sh = gc.create(os.path.basename(csvpath))
sh.share(username, perm_type='user', role='writer')
gc.import_csv(sh.id, content)
print("https://docs.google.com/spreadsheets/d/" + sh.id + "/edit")

All you need to do is get a service account with google sheets and google drive api enabled (read here Authentication — gspread 3.7.0 documentation how to do it). Save the client secrets json on your computer and change the path to it in the code. Also change username to your google account email (because the service account is the creator only it can see the sheet unless you share it with you first).

The script works great. I just select a file and use a trigger and 3 sec later it opens the file imported and ready in a google sheet with the same name as the file. I probably won’t connect it as a default for .csv files because I might just wanna use numbers sometimes but I think changing the default app to the keyboard maestro script shouldn’t be impossible with some googling.

2 Likes

Thank you @VictorBjorklund for sharing this! I’m definitely gonna give it a whirl.

1 Like

Thank you @emckillen for giving the idea that it could be automated! I open csv:s in google sheets everyday so this will save lots of time!