Create a Mac OS X Finder Service

Here are some notes on creating a Service for Mac OS X Finder. This will add an item to the Finder Services menu (available under the Finder menu and also by right-clicking on a file in Finder). This particular service will convert a simple .html file into a .rtf.

The basic commands you want to run on the file are:

  • textutil -convert rtf -output “outputfile.rtf” “inputfile.html”
  • touch -r “inputfile.html” “outputfile.rtf”

This will convert the file to RTF (first line) and copy the timestamps from the .html file to the .rtf file (second line).

  1. Launch Automator
  2. File » New » Service
  3. Set: Service receives select files or folders in Finder.app.
  4. Add an action: Run Shell Script. Paste in the following bash statements:

     set -e    # Exit on error
     # This will convert simple (stand-alone) html files to RTF.
        
     html_to_rtf () { 
         d2="$(dirname "$1")" # Do NOT need to escape quote in $()
         f2="$(basename "$1" .html)"
         if [ -d "$d2/$f2.resources" ] ; then return 0 ; fi
         if ! textutil -convert rtf -output "$d2/$f2.rtf" "$1"  ; then return 1 ; fi
         if ! touch -r "$1" "$d2/$f2.rtf" ; then return 1 ; fi
         rm "$1"
     }
        
     for f in "$@" ; do
         g=$(echo "$f" | tr "[:upper:]" "[:lower:]")
         if [[ "$g" = *".html" && -f "$f" && -r "$f" ]] ; then
             html_to_rtf "$f"
         fi
     done
    

Testing an Automator Service is a bother. You want to just press the Run button in Automator, to run it within Automator, but when you run it for real, you will have selected a file in Finder. For testing purposes only, add a step to the beginning of your Automator steps to Get Specified Finder Items, and select some files to test with. After you’ve finished testing, remove it.

File » Save » HTML to RTF

If you need to modify this service at a later date, it will be found in: /Users/username/Library/Services/HTML to RTF.workflow

Convert to PDF - OS X Command Line (Terminal)

To print to PDF (convert) most SINGLE PAGE files in OS X:

cupsfilter foo_name_here > foo.pdf 2>/dev/null

If you run this with a mult-page TIF as input, the output will truncate everything after the first page.

Combine Multiple Images to a Single PDF With Preview on Mac OS X

I wanted to combine multiple TIFF images into a single PDF on Mac OS X. Here’s how:

  • Start Preview.
  • File » Open » open all the files you want, using CMD-click to select.
  • Drag the thumbnails into the desired order
  • File » Print » PDF » Save as PDF

Removing an App From Spotlight

I wanted to remove Evernote from Spotlight.

It is easy enough to remove a Folder from Spotlight. Just go to System Preferences » Spotlight » Privacy, and drag any folder from Finder into the list. That folder is no longer indexed.

But the folders for Evernote, reported by others to meet this need, are ineffective. (I rebuilt the Spotlight index and they came back!)

  • ~/Library/Application Support/com.evernote.Evernote
  • ~/Library/Caches/com.evernote.Evernote

So I went looking for the importer for Evernote:

mdimport -L

That output includes:

/Applications/Evernote.app/Contents/Library/Spotlight/EvernoteSpotlightImporter.mdimporter

So I deleted that Folder and then rebuilt my Spotlight index with:

sudo mdutil -E /

Leaving Evernote

Evernote does not encrypt data at rest. Evernote does not apply “zero knowledge” encryption (where data in encrypted on the client and the provider has no ability to decrypt the customer’s data).

I’m sure Evernote is a fine company, but I see no reason to believe that their security team is any sharper than their development team, and there have been many defects in the application through the years. Eventually, I can expect a breach. I used to use Evernote as my file cabinet. I’ve decided it is simply irresponsible of me to continue to store tax records, medical records, bank statements, etc. in a cloud-based product which does not apply zero knowledge encryption.

Evernote, I’m leaving you. It will be a difficult separation, but I’ll manage somehow.

Some things I really liked about Evernote:

  • I use a Mac. My wife uses Windows. We both need access to our file cabinet. Evernote made that easy, and kept us synched.
  • The file cabinet metaphor has its limits. Not all data fits into a single spot in a hierarchy, plus lots of my stuff gets stashed in ‘the big pile.’ Evernote’s search tools just work better than Spotlight for me.
  • Separation of documents from app data and programs. Spotlight likes to show me every file. 99% of the time, I’m searching for a document. (Document includes saved web pages.)

I’m going to capture my strategy for leaving Evernote here. I’m going to capture the problems I encounter. I’m going to capture the reasons I do what I do, so that I won’t forget and revert.

##Requirements:

  • The main parties:
    • Bad guys must not be able to access documents. (Secure)
    • My wife and I have to be able to find the right documents quickly. (Accessible)
    • I/wife/executor should be able to get to it if my house burns to the ground and I get nothing out. (Persistent)
  • Must be able to export the documents (unless they live in the file system as well-titled files), in case the app/service is withdrawn.
  • Access when I’m away from home is a nice-to-have, but not a requirement.

##Alternatives:

  • Continue with Evernote as is. Why rejected: Unacceptable security risk of unencrypted data on server. Meets all other requirements.
  • Continue with Evernote, making all notebooks local-only. Why rejected: Not accessible to wife on daily basis. (Executor could get it from my off-site backups.) Meets all other requirements.
    • Note that simply copying the database from my Mac to my wife’s PC. Windows and Mac Evernote use different database formats.
  • Store documents in the file system. Plain old notes (as would be composed in Evernote) get stored in RTF or HTML or Markdown for portability. Not as accessible. Meets all other requirements.
    • My local file system is encrypted, as is my wife’s - providing security.
    • My local file system is backed up off-site with a service - providing persistence.
    • Spotlight (Mac) and Windows Search are just not as good at finding the right file as Evernote’s search and display.
  • Store documents in the file system, auto-import new/updated documents into local-only Evernote. Synch files with my wife. Never update an Evernote document from the Evernote UI.
    • If I could pull this off, it might meet all requirements, with the down-side of doubling my data size. I currently have 5 GB in Evernote. That’s not a terrible cost.
    • Or turn this around and only update the documents in (local) Evernote, export the recently updated items, and sync via the file system to my wife’s PC.
  • Migrate Evernote to OneNote. OneNote meets the security requirement technically, but not practically; it misses the export requirement.
    • Does not store data locally on the Mac. That’s a big miss on accessibility. I’m not going to rely on Internet availability to get my documents. If MS drops the service, I lose Mac access.
    • You can password protect a OneNote “notebook section.” Microsoft says they can’t decrypt it. You may have to protect it using the desktop client - it isn’t clear that www.onenote.com can add the password.
    • You have to remember to password each new section and you have to enter the section’s password to open it.
    • “Password-protected sections aren’t included in notebook searches. To include a protected section in a search, you’ll have to unlock the section first.”)
    • Export can create only a single file for exports. i.e. You can export a single note to a document or you can export an entire notebook to one document.

What I really want is the Evernote user interface on top of the native file system.

##Things I’m Trying In Order to Make Spotlight a Better Fit

If I’m going to use Spotlight, I need to make it find the documents I’m looking for most often.

  • Change indexing:
    • Exclude folders:
      • I’m going to exclude most folders, and use Spotlight solely for folders where I store documents. For other files, I’ll just use ‘find’ in a Terminal window.
      • I’ve read that Spotlight is hard-wired not to index source code.
    • While I’m transitioning, I want to remove Evernote from Spotlight but keep the data as a backup. These were ineffective at removing Evernote. See this story.
      • Exclude folder ~/Library/Application Support/com.evernote.Evernote
      • Exclude folder ~/Library/Caches/com.evernote.Evernote
    • Ultimately, I deleted the .mdimporter file from /Applications/Evernote.app/Library/Spotlight
    • Note: If you want to rebuild the Spotlight index: sudo mdutil -E /
    • Ugh. Apparently, it won’t index .html files unless you have XCode. Install XCode.
    • Here’s how to add a file type to be indexed, using the rich text importer: http://robin.wenglewski.de/posts/2015/05/26/osx-markdown-indexing-knowledge-management/
  • Change searching:
    • Go to System Preferences » Spotlight » Search Results
      • There’s not really enough granularity/clarity here. Make some guesses. Exclude everything except documents. I’m searching only:
        • Applications
        • Developer
        • Documents
        • Folders
        • Images
        • Movies
        • Music
        • Other
        • PDF Documents
        • Presentations
        • Spreadsheets
      • You could control the order in which items were displayed in the search results by re-ordering this list in older versions of OS X, but cannot do so any longer.
    • If you want better control over the display of search results, start your search with Alt-Cmd-Space instead of Cmd-Space
    • There are tales that you can edit com.apple.Spotlight.plist in ~/Library/Preferences (with an editor that understands binary plist files such as BBEdit or TextWrangler) and rearrange the dict items in the array. You may have to reboot immediately afterward. You may have to do this in single-user mode/special-boot-mode.
    • Alfred doesn’t find things I think it ought to find. (Yes, I used the “in” keyword.) It just doesn’t find things that Spotlight does.
    • Spotlight puts my .html documents under the category “Developer”. I want them listed as “Documents”. I can’t find a way to make it do that. I looked for about a half day.
    • This will find all your mdimporters (and it is a manageably sized list): find / -name \*.mdimporter -print 2>/dev/null

Synchronizing

I used to use Evernote to sync my documents with my wife. Now that my documents are in the file system, I need another method. Mostly, I am the family member who files things, so I can live with one-way replication. That’s good because Unison 2.48.4 (on my wife’s PC and on my Mac) has a bug where it always creates files with 600 permissions. (Yes, I set the options and umask appropriately.) If they fix it, Unison would allow me to use 2-ways synch, but for now I’m using rsync.

  • I installed Cygwin, rsync, ssh, and unison I mostly used this as a guide for setting up ssh.
  • I used this command line on my Mac to sync the files:
    • rsync -avz –delete –exclude ‘.DS_Store’ /Users/kevin/Sync/Docs kevin@suedell:/cygdrive/c/users/susan/sync > “/tmp/sync-to-sue.log.$mm.$dd” 2>&1 &
  • I will eventually set up a cron task to run this script daily. (For now, I simply launch it from .bash_profile.)

          #!/bin/bash
          mm=`date '+%m'`
          dd=`date '+%d'`
          yyyy=`date '+%Y'`
          marker="/Users/kevin/.sync-to-sue/done-$yyyy.$mm.$dd"
    
          try_to_sync() {
              if ! ping -c 1 -t 1 192.168.8.20  ; then
                  echo "Unable to ping Sue"
                  return 0
              fi
              echo "Syncing to Sue"
              rsync -avz --delete --exclude '.DS_Store' /Users/kevin/Sync/Docs kevin@suedell:/cygdrive/c/users/susan/sync > "/tmp/sync-to-sue.log.$mm.$dd" 2>&1 &
              if [ $? -eq 0 ]; then
                  # nothing
                  echo "Launched rsync to Sue"
                  touch "$marker"
              else
                  echo "Failed to launch rsync to Sue"
              fi
          }
            
          mkdir ~/.sync-to-sue 2>/dev/null
    
          if [ -r "$marker" ] ; then
              echo "NOT syncing to Sue. Already happened."
          else
              echo "Starting sync.  Did not find $marker"
              try_to_sync
          fi
    

Investigating:

  • I need to find un-OCR image PDF files and run them through OCR.
  • I’d like to put all my documents in ~/Documents/really-documents and all my data in ~/Documents/really-data. One of the nice things about using Evernote is that it contained solely documents. However, I also want to put my tax forms (as PDFs) in the same directory as my TurboTax data files. I can’t have it both ways. (I’m not going to use symlinks, links, or Aliases – they are too fragile.) Which is more useful?
    • Another example: Do I want my readme.txt with its source code or in ~/Documents/documents-really? I think this one is obviously “with the code,” but how do I write a simple rule?
    • The “file cabinet” metaphor almost works. If I would put the printed doc in a file cabinet, it should go in really-documents. Source code would never go in a file cabinet (except, perhaps, with a patent filing or a copyright filing). Data lives on the computer in really-data. But what about things like “Notes on how I am currently doing GTD”? That’s clearly a document, not data, but it isn’t a static document, so if I filed it, I’d be planning to pull it back out and revise it.
    • It seems like maybe:
      • Static documents from others go in really-documents.
      • Documents that have multiple viewers go in really-documents.
      • Source code does not go in really-documents. It isn’t data. It goes somewhere else.
      • Data (typically not 1-to-1 mappable to a document) openable only by one app goes in really-data.
    • What are “Documents”?
      • .pdf
      • .doc and .docx and .rtf and .rtfd
      • .xls and .xlsx and some .csv
      • Visio diagrams
      • Most .txt files (text documents)
      • .html and .mht files (and the standard variations on those names) that are not part of a web site I’m developing/analyzing
      • Emails extracted from an email system for a permanent record. (May include .html or Outlook .msg files.)
      • .opml that are really outlines/checklists
    • Non-documents:
      • source code
      • .html, and .mht files (and the standard variations on those names) that are part of a web site I’m developing/analyzing (they are really just a special type of source files)
      • TurboTax and Quicken data
      • Some .csv
      • Occasional .txt files (text data)
      • Zip files, tar, gzip, bzip, etc.
      • Emails in an email system.
      • Backups (data and document backups)
      • .opml that are really my podcast/RSS (or similar) state
    • Maybe this makes sense:
      • grep-able stuff goes in really-documents, unless it is source code
      • Non-grep-able stuff goes in really-data
      • Source code goes in source-code
      • What else exists?
        • Audio recordings, made during project meetings.
        • Are eBooks documents or data? I think maybe they are documents, but they are really big and may be un-searchable. Are my Kindle/Calibre books data or documents?
          • In favor of declaring them data:
            • I have about 3GB (2017). If I make them documents, that will consume much of my cloud storage.
          • In favor of declaring them documents:
            • If someone writes an mdimporter, I can search them.
            • They are, logically, documents. What is a physical book if not a large document?
            • Most of them can be rendered by more than one reader app. Render-by-multiple-apps is a ‘document’ heuristic.
            • I might want to share them with my wife. She’ll think ‘document’.
          • Decision: I’m calling them documents, but I’m putting them in Sync/Books, parallel to Sync/Docs, because I may want to:
            • Synch/not-synch them, separate from personal documents.
            • Search/not-search them, separate from personal documents.
            • Note: We put personal paper documents into a file cabinet, and books in a bookcase. They are stored similarly, but in different containers.
        • I’m going to treat source code like eBooks. It goes in Sync/code, as a peer of Sync/Docs.
        • What about a spreadsheet showing health data like blood pressure and blood chemistry?
        • What about a camping checklist?
        • Where do I put a Drupal web site in development? Clearly not a document. Not data (except for the MySQL data). Not really source code.
        • Music
        • Movies + TV + Video
        • Ableton Live files
        • Punch Pro home plans
        • Genealogy data
        • Audio books
        • Tiddlywikis
        • Virtual machines
      • What about things like easy-rsa, where I have a mix of code and data? I think there are 3 kinds of programs:
        • Apps (foo.app)
        • bin (stand-alone executable files and executable scripts)
        • Packages: Things like nirv and easy-rsa. Do I want to park these under ~/Packages or ~/bin? What about packages that I “make install” after un-tarring them into a directory?

Home Folder:

  • Applications
  • backups
  • bin
  • Desktop
  • Documents (don’t put anything here unless you must)
  • Downloads
  • jumbo
  • Library
  • Movies
  • Music
  • Packages (or should these go into bin?)
  • Pictures
  • Public
  • Sync (This is where I really store documents.)
  • temp

Windows 10 - I Want the Old Dialog to Add a User Without an Email or a MSN or a Phone Number

I know how to add users to old Windows. Microsoft changed it and made it more complicated with Windows 10. Here’s how to find the old add-user dialog.

  • Start » Run » control userpassword2
  • Press Add
  • Click “Sign in without a Microsoft account (not recommended)” down at the bottom of the dialog.

Light Bulb Info

Candelabra means e-12 (or E12) socket/base.

GTD With Nirvana Refresher - 2017

  • Tasks are tangible (physical, visible)
  • Lists
    • Inbox
    • Next Actions (NA)
    • Waiting for
    • Projects
    • Later
    • Someday
    • Focus: Add a star to it if I really need to do it before I knock off for the day (Sat+Sun = 1 “day”).
      • Tag it with “weekend” if I can’t star it for today, but I want to consider starring it on Friday night.
  • Calendar

Inbox:

  • Barrier to entry is low
  • Process in sequence
  • Actionable? Toss it, file as reference, someday/maybe it, schedule to revisit (once) OR…
    • Can i handle it in 60 seconds? Just Do It.
    • Capture the tangible NA; if it is a stand-alone, capture it in NA List; else capture it in a project
    • NA list should be exclusively for “do ASAP, if in context”
  • Blocked?
    • Move to Waiting For and put a nag/fup date on it
  • Is it a Project (multi-step)?
    • Create a project list, and capture the project’s NA
  • Contexts
    • Important to David Allen. Not so much to me.
    • I care about work role vs personal (“kpk”) role
    • Tag actions/projects with role (“Area” in Nirvana)
  • Someday List is a problem for me because it is huge.
    • Put some stuff into Later. Higher priority? Really committed?
    • Put the inconsequential or the lower priority or the really just “maybe” stuff into Someday.
  • Don’t dilute the calendar. Only put hard commitments there. Will happen at that time.

Weekly Review - Check:

  • Every project has a NA
  • For every NA, will I really do it this week, time permitting? If not, Someday it.
  • Are my NAs things I can do in one sitting? Subdivide, if not.
  • Later list:
    • Move things to NA list, if NA is true.
    • Move to “xxxx” list, if I’m not realistically committed to do it in 6 months but I don’t want to give it up.
    • Move to “give it up” list if I’m giving it up. Capture why.
  • Someday list:
    • ONLY process this list once each quarter (March, June, September, December)
  • What can I do with my boys for family time this week?
  • Review my Read reference list
  • Review my Covey Roles reference list
  • Clean-up/migrate any other Reference lists. Do they really need to be in Nirvana?
  • Are there any big picture things I need to meditate on how to improve/handle?
  • “recognize and excel in what really counts — and to aim for less than perfect in everything else. If you’re shocked and feel like this seems completely unfair, I’m guessing that you probably performed very well in school where perfectionism is encouraged.”

Read Reference list:

  • Entertainment
  • Enrichment/self-improvement
  • Work (ATT or kpk work). Move these to project or stand-alone if I’m going to get to them this week

Misc Notes:

Excel Drag-and-drop Editing

I never can remember these:

  • Move and overwrite = just drag and drop.
  • Move and insert = shift drag and drop.
  • Move and copy = control drag and drop