-
If you install Python on your Mac, you can run the python code.
-
You can build your python code into a pyc, and run that on a Mac that has python installed.
-
Personally, because of the nature of the task I had, which generated and displayed lists, I built my python into OpenOffice Calc, and it would run on any Mac that had OpenOffice Calc installed.
What does this part mean? Does OpenOffice use Python as its scripting language?
Without seeing your full current code, here’s a quick & simplified example that runs in App Script right in Google Docs:
/**
* @OnlyCurrentDoc
*/
function replaceKeywords() {
// 1. Define your dictionary of keywords and their expansions
const templates = {
'example': 'https://www.example.com',
'abc': 'Alphabetical Book Club'
};
// 2. Get the current active document and its body
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
// 3. Loop through each item in the dictionary
for (const key in templates) {
// 4. Construct the regex search pattern.
// We need to escape the brackets: \[\[key\]\]
// In a JavaScript string literal, that requires double backslashes: \\[\\[key\\]\\]
const searchPattern = "\\[\\[" + key + "\\]\\]";
const replacementText = templates[key];
// 5. Execute the replacement across the entire document body
body.replaceText(searchPattern, replacementText);
}
}
/**
* Creates a custom menu in the Google Docs UI when the document is opened.
*/
function onOpen() {
DocumentApp.getUi() // Gets the user interface environment for the document.
.createMenu('Keyword Tools') // Creates a top-level menu named "Keyword Tools".
.addItem('Run Keyword Replacement', 'replaceKeywords') // Adds a menu item that calls the 'replaceKeywords' function.
.addToUi(); // Puts the menu into the document's menu bar.
}
Once you save that script, any other signed-in GDoc editor will then see the “Keyword Tools” menu added by the script and can run the replacement right there in the doc.
This simplified example has the replacements hardcoded at the top. In a real-world example, you’d probably keep that list somewhere separate (like a GSheet) for ease of updates.
But still, even this simplified example should be easier for your users (they just click the menu entry without having to download or install anything, and when you update the script with new templates, it’s automatically updated for all your editors too).
In this particular case, I just asked AI (Gemini) to write that code from scratch because I didn’t have an existing Python script to work from. Since you do, you can instead copy and paste your current snippet and ask it to “port” your Python into Google Docs Apps Script for you. Porting is just jargon for converting from one programming language to another while retaining the same logic.
There’s an AI built right into Google Docs (the Gemini “sparkle” button, or Tools → Gemini), or you can use any LLM you like.
And just as an aside: I am not advocating for Javascript (Google Docs Apps Script) over Python. From a programming perspective, both are extremely popular, modernized, and well-maintained languages. Either is a fine choice to learn from. Neither is better or worse for a simple string manipulation program. Both are easier to learn, run, debug, and distribute than compiled languages would typically be.
However, from a usability perspective, what I AM suggesting is that you meet your users (coworkers?) where they’re at. Make your program as easy to use as possible for them. Minimize their friction even if it means a little more work for you.
In this particular case, it just so happens that Google Docs has its own scripting system built-in, and that system happens to use Javascript/Apps Script. In other ecosystems, like if you guys were using OpenOffice/LibreOffice, Python might be a drop-in fit! (And in yet other systems, like games, Lua might be preferable instead.)
Thankfully, it only takes a few minutes (with AI help) to convert your Python code into an Apps Script that lives and runs natively inside the GDoc. Over time, that should save both you (as the developer) and your users time, since you wouldn’t have to re-compile, re-sign, and re-distribute a binary package every time you need to make a change, and they wouldn’t have to jump through hoops or encounter scary warnings just to run your program.
But that shouldn’t stop you from learning Python, or pressure you into learning Javascript. Both are great for this use case; it just so happens that your documents already live in the Google Docs world, so you might as well run your code there.
This situation is by no means unique to Python, BTW. Real-world software development is often like 50% research and planning, 25% coding, and 25% distribution headaches. The distribution part is often as difficult (or more so) than the actual code, especially for simple business apps. The Web makes that part somewhat easier, but it’s often still a pain (even in Javascript!).
What I used to do is just have python loaded locally so you can run your .py file with the python.exe .
So in a .bat file, it would be something like this - C:\python\python.exe yourfile.py
Now, I don’t have my code in front of me, but that’s the basics. Just run your .py file in a .bat file that uses the python.exe
Then since this needed to be run daily, I would set up Task Scheduler to run the .bat file.
Now I’m not a Mac guy, but it must have some similar ability to run a .bat file. I hope.
Anyway, the .bat works like an .exe.
It would be a shell script under Macs, but I think the issue here is that he’s wanting to distribute his code for other coworkers to run (at least that was the case last year). They may not have a Python interpreter installed, or know how to use the Mac terminal (or maybe they do, not sure?)
MacOS comes with Python pre-installed, although it may not be the latest version.
Yes, mine running MacOS 15.something and 26.something both have Python 3.9, but I wasn’t sure if it came with the OS or was part of XCode.
Just starting a script with a line like #!/usr/bin/python3 should be enough for it to work on a Mac. The difficult thing will be if there are additional Python packages that are needed. Once you need to explain to a user how to run pip or setup a venv, then you’re right back to the headaches of distribution.
I think that used to be the case, but maybe now it only comes with xcode? I’m not 100% sure.
OO / Libre has Python as -one- of the scripting languages.
The ‘VBA’ equivalent in OO/Libre is badly limited, and not useful for most of the things VBA is used for in Excel, so Python fills part of that space. It works ok on Mac, and on some versions of Linux, which makes it sort of portable for complex programming tasks which need a spreadsheet or document interface
For this you would use a .pyz package. A python script packaged with dependencies into on big ball-of-code. “Python Zip Application”
“Python Zip Application” is close to what OP asked for, but note that I endorse @reply 's suggestion of Apps/Script. I used OpenOffice python because it matched my particular task.
I am sorry I have not replied more frequently to this thread. I am trying to sort the great advice given by @Reply and many others. I am still working to get a handle on all said but I gotta say this is all fantastic. I seriously appreciate all the advice and help being given. It is above and beyond.
You are all the best…truly.
Thank you
Good luck
You have like 10 mediocre options and no great ones…
I took your advice and it works great. I had my AI convert the Python code to AppScript and it did in minutes what I suspect would take even the most experienced programmer hours to do. And the AI did it perfectly.
I got it running in Google Docs, made a few tweaks which I had to fiddle with for a few hours (a lot of that was testing…spend a minute making a tweak and test again…rinse and repeat looking for those edge cases).
Thanks a lot for your advice and help. I owe you a drink (or three).
Indeed, thanks to all here. SDMB is still the best.
Cool, glad it works! Hopefully that makes the workflow a little easier for everyone.