How to support this blog?

To support this blog, you can hire me as an OmegaT consultant/trainer, or you can send translation and project management jobs my way.

Search the site:

Export your Numbers file to a PDF in the same folder

use AppleScript version "2.4" -- Yosemite (10.10) or later

use scripting additions


property alert_exists : "The PDF already exists. Continue?"

property dialog_yes : "Yes"

property dialog_no : "No"

property export_complete : "The PDF has been exported"


# this script exports a PDF of the frontmost Numbers file

# the Numbers file is saved before export to make sure that it exists

# the PDF file is exported to the same folder as the original file

# if the name of the original is myName.numbers, the PDF name is myName.pdf

# if the PDF already exists it is possible to cancel the export

# once the export is completed, Numbers displays an alert

# and Finder opens the enclosing folder


tell application "Numbers"

# this script exports a PDF of the frontmost Numbers file

set myDocument to (item 1 of (document of windows whose index is 1))

# the file is saved before export to make sure that it exists

save myDocument

set myDocumentName to name of myDocument

set myDocumentPath to file of myDocument as text

end tell


tell application "Finder"

# the PDF file is exported to the same folder as the original file

set myDocumentContainer to (container of file myDocumentPath) as text

end tell


# if the name of the original is myName.numbers, the PDF name is myName.pdf

set myExportedPDF to myDocumentContainer & myDocumentName & ".pdf"


tell application "System Events"

# if the PDF already exists it is possible to cancel the export

if exists file myExportedPDF then

display alert alert_exists as warning buttons {dialog_yes, dialog_no} cancel button dialog_no

end if

end tell


tell application "Numbers"

(close access (open for access (myExportedPDF)))

export myDocument to file myExportedPDF as PDF with properties {image quality:Best}

# once the export is completed, Numbers displays an alert

display alert export_complete

end tell


tell application "Finder"

# and Finder opens the enclosing folder

activate

open myDocumentContainer

end tell


# here again, save this script as an Application, with a funny name

# so that you can easily call with with Spotlight

# I chose "> Numbers PDF"

Building "vanilla" emacs on macOS, with MacPorts, and more...

6/12/2024 update

My version of macOS is too old to be able to use brew reliably since the package manager deprecated support for Monterey (macOS 12) as of its latest release. I had to remove all traces of brew on my machine and moved to MacPorts that still provides support back to macOS 10.5 (Leopard !!!).

I modified the text to only cover a MacPorts installation. People who rely on brew will know how to change the commands. I have also updated a few links.


Table of contents

  1. Free software = build your software yourself
  2. Required dependencies for building emacs on macOS
  3. Extra dependencies that will add features to your emacs
  4. 8 lines of instructions
  5. emacs documentation
  6. To use emacs from the command line
  7. Updating the code requires 2 instructions
  8. Free Software = you can write code and contribute
  9. References

This is Free Software!

Lots of people seem to wonder, "what is the best emacs for macOS"?

Their criteria for "best" being not always clear, the answer I systematically give is: "Clone the repository and build it yourself. This is free software!"

Since I always forget the dependencies and the steps, this page is a memo for myself, and for curious people who want to try themselves.

Note: I am not a programmer. I just follow instructions. There is nothing magic in the few instruction lines that follow. Before, or after you've cloned emacs, you can read the INSTALL.REPO file where basically everything I write here is found, along with the README and the INSTALL files where you'll find additional or redundant information. It's basically all there. This page is just a summary for me.

ToC

Required dependencies

The dependencies below are the minimum emacs requires, and you can find them by running ./autogen.sh first and then ./configure yourself before using MacPorts to install them: the two scripts will just choke every time they don't find the required libraries.

What I did to come up with that list is just add dependencies until the scripts ran their course without error.

If this is your first "development" attempt, you will need the XCode command line tools, basically because you'll need gcc and git for the whole process. Follow the instructions on the "Intalling MacPorts" page to find how to install them. And don’t forget to install MacPorts too.

The first time you run git, for example to clone emacs, macOS will tell you that you need to install them and prompt you with a nice dialog.

The required dependencies are the following:

  • Autoconf
    "Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages."
  • texinfo
    "Texinfo is the official documentation format of the GNU project."
  • GNU Mailutils
    "Mailutils is a swiss army knife of electronic mail handling. It offers a rich set of utilities and daemons for processing e-mail."
  • GnuTLS
    "GnuTLS is a secure communications library implementing the SSL, TLS and DTLS protocols and technologies around them."

ToC

Extra dependencies

I sent the link to this article to the emacs-devel mailing list for verification and Pankaj Jangid was nice enough to tell me about his own experiences and suggested a list of non-required but recommended packages that emacs would notice during the configuration process. Alan Third, the ns-port maintainer, also chimed in to indicate that some of Pankaj proposed libraries were in fact ignored since the image types they correspond to are handled by macOS proper.

The recomended dependencies are the following:

  • librsvg
    "This is librsvg - A small library to render Scalable Vector Graphics (SVG), associated with the GNOME Project."
  • libxpm
    "X11 pixmap library"
  • lcms2
    "Little CMS intends to be a small-footprint color management engine, with special focus on accuracy and performance."
  • jansson
    "Jansson is a C library for encoding, decoding and manipulating JSON data."

If you want to install the above recommended dependencies, you'll need to add a port install instruction as shown below.

ToC

The instructions

# install required dependencies
# or jump to "configure, etc." below and install them one by one
sudo port install autoconf texinfo gnutls mailutils

# install recommended dependencies, but only after you've checked what they do by following the links above...
sudo port install librsvg libxpm lcms2 jansson
# clone emacs
# URL: https://savannah.gnu.org/projects/emacs
git clone -b master git://git.sv.gnu.org/emacs.git

# configure, build and install emacs
cd emacs
./autogen.sh
./configure
make install

Et voilà! Emacs.app now resides in emacs/nextstep/Emacs.app.

ToC

Documentation

I don't suppose you'd want to install emacs from scratch without knowing how to use it, but if that's the case, and that's totally OK, emacs comes with thousands of pages of manuals that are just a ctrl-h i away.

That shortcut means hit the control key, hold it pressed, hit the h key, release both, and hit the i key. That shortcut calls the info function, which bring up the list of manuals included in emacs.

You can also start a tutorial with ctrl-h t, which means hit the control key, hold it pressed, hit the h key, release both, and hit the t key. That shortcut calls the help-with-tutorial function.

The manuals are online, if you feel more confortable reading in a web browser: GNU Emacs Manuals Online

ToC

A few extra settings

If you need to use emacs from the command line you may need to update your .profile file with aliases like this:

alias emacs='path/to/emacs/nextstep/Emacs.app/Contents/MacOS/Emacs'
alias emacsclient='path/to/emacs/nextstep/Emacs.app/Contents/MacOS/bin/emacsclient'
alias ctags='path/to/emacs/nextstep/Emacs.app/Contents/MacOS/bin/ctags'
alias ebrowse='path/to/emacs/nextstep/Emacs.app/Contents/MacOS/bin/ebrowse'
alias etags='path/to/emacs/nextstep/Emacs.app/Contents/MacOS/bin/etags'

and that's basically it.

ToC

Updating the thing

The first time you build emacs, along with installing all the dependencies, etc. might take some time, maybe a good 30 minutes, maybe more. But then, you end up with a configuration where you just need to update the code once in a while, and make install the thing again to have the latest version running.

Basically, all is needed is to run this:

# inside the cloned emacs directory
# update the code
git pull

# build and install the new version
make install

And the next time to start emacs, you run the lastest master branch code.

ToC

This it Free Software! 2

The whole point of Free Software is that is gives you the tools necessary to understand what is going on, to learn how to do things yourself and to control your environement.

So, yes, emacs is free software, and now you're all set to play with the code and do your own thing, that will eventually lead to first contribute small things, and then bigger and bigger things to emacs proper.

For that, you just need to create your own development branch and code there:

# inside the cloned emacs directory
# update the code, just to have the latest one
git pull

# create your development/test branch, for example "myEmacs"
git checkout -b myEmacs

# open that new branch in Finder
open .

Everything you do there will never impact the master branch from which you have built emacs. You can always git checkout master back to go back to a clean slate (git will eventually ask you to git stash away your modifications before switching to master, so just follow the instructions).

ToC

References

Now, you may want to know a bit more about Emacs Lisp, about git, about how to contribute to emacs, so here are some references:

  • The "Introduction to Programming in Emacs Lisp" is the entry point for Emacs Lisp development. It is available from inside emacs (type ctrl-h i to find the list of manuals available right at your finger tips) and also online:
    An Introduction to Programming in Emacs Lisp
  • git comes with excellent documentation, and a free book too:
    Git Documentation
  • If you want to practice your Emacs Lisp skills, the "Exercism" site has a track for you:
    Emacs Lisp on Exercism
  • You will quickly find that you need to have a good Emacs Lisp reference to go further. emacs provides you with an excellent reference for pretty much everything you need to know, here again, just a ctrl-h i away, but it is also online:
    GNU Emacs Lisp Reference Manual
  • If you need general help, there is a help-gnu-emacs list and for development help there is the emacs-devel list, along with a lot of other emacs related lists, hosted on the emacs development site:
    emacs - Mailing Lists
  • And here is a tutorial about the procedure to follow if you want to propose your code for inclusion into emacs, by Colin Woodbury:
    Contributing to Emacs

ToC

Everything you wanted to know about modifying application shortcuts, and more...

Modifying application shortcuts

Or, how to spend two hours on your machine on a Sunday morning, when you could go take a walk instead...

Here I talk about an itch I felt the need to scratch this morning, and about 2 applications: CheatSheet, and customShortcuts, and I put a lot of references at the end, so have fun reading!


You can change shortcuts in System Preferences > Keyboard > Shortcuts > App Shortcuts

Most of the things you'll ever need to do can be done there.

But then, some can't.

This morning, I realized that in Mail.app, moving from Delete (Cmd+Del) to Mark as Read (Shift+Cmd+U) when I read and sort my mail, was not what I wanted.

When I read my mail, there are obvious deletes, but a lot of my casual mail can just be not read (discussion lists, where only a few threads are interesting), or specifically marked for later reference. But moving from Cmd+Del to Shift+Cmd+U involves a lot of friction and I want to get rid of that.

I want to have something like:

  • Cmd+Del = Mark as Read (or Mark as Unread, depending on context)
  • Shift+Cmd+Del = Delete
    and since that one is taken by "Erase Deleted Items > In All Accounts...", which I never use, I'd move that item to
  • Alt+Shift+Cmd+Del = Erase Deleted Items > In All Accounts...

That way, I have my morning "mail discussion parsing" workflow all centered on Del, which is a Good Thing™.

The problem is that the System Preference panel has its ideas on what can and cannot be done, and won't allow us to assign Cmd+Del to anything but Delete...

I know there are solutions that give you access to key bindings data, things that are really interesting and let you dive into the intricacies of the OS, but I was not really in that mood this morning (I put all the references at the bottom, there is plenty to read and play with, when you have time).

I remembered that there was an app that gives you all the shortcuts available in any given app (at least apps that live into the macOS GUI system, i.e. basically anything that has a real macOS menu at the top of the window, including Java apps like OmegaT, Electron apps like TMXEditor, etc.), the app is "CheatSheet" and can be found here:

https://www.mediaatelier.com/CheatSheet/

Just out of renewed curiosity, I decided to take a peek, just in case...

And there, behold! There is a link to that companion app: "CustomShortcuts" that (also) "works hand in hand with CheatSheet" by allowing you to edit shortcuts directly in the CheatSheet interface, which is pretty neat...

https://www.houdah.com/customShortcuts/

After a quick download and a few authorizations, I can now do what I wanted to do (assign Cmd+Del to Mark as Read, etc.), plus customShortcuts has autocompletion of menu item names, so you don't have to actually check the target application interface and worry about whether "..." is three dots, or an ellipsis… (← this thing).

Et voilà, I've got my workflow fixed now, I can spend the rest of my Sunday with my heart at ease, and here are the references I promised:


References

Post scriptum

You may want to give CheatSheet a "longish" delay before appearing when you hit Cmd, because it gets tiring real quick to have it pop up while you think about the shortcut you actually want to hit while holding Cmd, which really happens all the time...

In 2009, I had put together a similar thing on how to play with keybindings in the shell. It is here:
Bash (command line) shortcuts

Popular, if not outdated, posts...

.docx .NET .pptx .sdf .xlsx AASync accented letters Accessibility Accessibility Inspector Alan Kay alignment Apple AppleScript ApplescriptObjC AppleTrans applications Aquamacs Arabic archive Automator backup bash BBEdit Better Call Saul bug Butler C Calculator Calendar Chinese Cocoa Command line CSV CSVConverter database defaults Devon Dictionary DITA DocBook Dock Doxygen EDICT Emacs emacs lisp ergonomics Excel external disk file formats file system File2XLIFF4j Finder Fink Font français Free software FSF Fun Get A Mac git GNU GPL Guido Van Rossum Heartsome Homebrew HTML IceCat Illustrator InDesign input system ITS iWork Japanese Java Java Properties Viewer Java Web Start json keybindings keyboard Keynote killall launchd LISA lisp locale4j localisation MacPorts Mail markdown MARTIF to TBX Converter Maxprograms Mono MS Office NeoOffice Numbers OASIS Ocelot ODF Okapi OLPC OLT OmegaT OnMyCommand oo2po OOXML Open Solaris OpenDocument OpenOffice.org OpenWordFast org-mode OSX Pages PDF PDFPen PlainCalc PO Preview programming python QA Quick Look QuickSilver QuickTime Player Rainbow RAM reggy regular expressions review rsync RTFCleaner Safari Santa Claus scanner Script Debugger Script Editor scripting scripting additions sdf2txt security Services shell shortcuts Skim sleep Smultron Snow Leopard Spaces Spanish spellchecking Spotlight SRX standards StarOffice Stingray Study SubEthaEdit Swordfish System Events System Preferences TBX TBXMaker Terminal text editing TextEdit TextMate TextWrangler The Tool Kit Time Capsule Time Machine tmutil TMX TMX Editor TMXValidator transifex Translate Toolkit translation Transmug troubleshooting TS TTX TXML UI Browser UI scripting Unix VBA vi Virtaal VirtualBox VLC W3C WebKit WHATWG Windows Wine Word WordFast wordpress writing Xcode XLIFF xml XO xslt YAML ZFS Zip