Forum Archive

Copy markdown to external app

aidensala

I have a script that scrapes info from data sites and then formats it into a markdown file that makes it easy for me to read. I like to read my markdown files using the Bear app, and to do this i have to export my markdown file from pythonista by clicking share and then selecting the "copy to Bear" option. Is there any way to do this using code? thanks for any help...

cvp

@aidensala You can use console.open_in(file) to present the standard open_in window BUT you can't preselect the app you want, you will have to do it manually.

There exists a solution by a Pythonista script that
- copies your text file to the clipboard
- starts the Apple Shortcuts app with a shortcut that will:
- get the file from the clipboard
- give it a name (optional)
- open_in the file and setting "does not display the menu", thus you can there preselect the app you want

Shortcut here

import clipboard
import webbrowser

url = 'shortcuts://x-callback-url/run-shortcut?name=OpenFileFromPythonistaInOneApp'

with open('myfile.md') as fil:
    c = fil.read()

clipboard.set(c)
webbrowser.open(url)
mikael

@aidensala, there is also an extensive URL scheme for bear (google it, they have nice docs). With it, you can pass a file to be created in bear as a Base64-encoded URL parameter:

bear://x-callback-url/add-file?filename=test.gif&id=4EDAF0D1-2EFF-4190-BC1D-67D9BAE49BA9-28433-000187BAA3D182EF&mode=append&file=R0lGODlhAQABAIAAAP%2F%2F%2F%2F%2F%2F%2FyH5BAEKAAEALAAAAAABAAEAAAICTAEAOw%3D%3D
cvp

@mikael very good idea, I never thought about the url scheme to the wanted app 😢

aidensala

@mikael @cvp perfect, just what i needed. thanks guys!