Collapsing DEVONthink groups via AppleScript

I’ve been moving to a tag-based system for organizing content in DEVONthink. All of my content for each database goes into a single group called “reference.” If I want to find something, I search the hierarchical tag structure instead of diving into some arbitrary list of groups.

But I still have groups that I’d like to collapse into the reference group. So I wrote an AppleScript to perform this action. Notably, most of the action is in the processGroup() handler which is recursive because we do not know how deep the group hierarchy goes.

Here’s the script if it’s something you can use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-- collapse all groups into a single reference group
-- Created by Alan Duncan on 2015-11-23 03-15-56
-- Copyright (c) 2015 Alan K. Duncan.
-- Distributed under the terms of the MIT license

-- some error codes we might encounter
property InvalidRecordIndexError : -1719

-- warning string template
property ConfirmText : "Collapse all groups in database: "

-- name of groups that we don't want to move contents of
property ExcludedRecordNames : {"Inbox", "Tags", "Mobile Sync", "Trash", "reference"}

-- the reference group
global refGroup

-- list of groups to delete
global deleteGroups

tell application "DEVONthink Pro"
set questionText to ConfirmText & name of current database & "?"
set confirm to display dialog questionText buttons {"Yes", "No"} default button 2
set answer to button returned of confirm
if answer is equal to "Yes" then
set deleteGroups to {}
set refGroup to referenceGroup(current database) of me
tell current database
repeat with aRecord in (every record whose type is group)
if name of aRecord is not in ExcludedRecordNames then
-- this is a legitimate group to process
processGroup(aRecord) of me
-- this group has been processed; it can be deleted
set end of deleteGroups to aRecord
end if
end repeat

cleanupGroups() of me
end tell
end if
end tell

-- remove all groups that are marked for deletion
on cleanupGroups()
tell application "DEVONthink Pro"
repeat with deleteGroup in deleteGroups
delete record deleteGroup
end repeat
end tell
end cleanupGroups

-- recursively process groups
on processGroup(aGroup)
tell application "DEVONthink Pro"
set theChildren to children of aGroup
repeat with aRecord in theChildren
-- if this child is a group, then enter recursively
if type of aRecord is group then
processGroup(aRecord) of me
else
move record aRecord to refGroup
end if
end repeat
end tell
end processGroup

-- return the reference group, creating it if it doesn't exist
on referenceGroup(db)
using terms from application "DEVONthink Pro"
tell db
try
set referenceGroup to the first record whose name is "reference"
on error error_message number error_number
if error_number is InvalidRecordIndexError then
-- try to create a group "reference"
set refGroup to create record with {name:"reference", type:group} in root
end if
end try
end tell
end using terms from
end referenceGroup

A minimalist mind

To deal with the explosion of information available to us, we’re told to avoid the filter bubble by seeking out a variety of sources. Or we’re told to pursue a low information diet. But we’re also told that to be informed is one of the duties of citizenship. What are we to do? Here are some other options:

  1. Stop caring about what doesn’t affect you. There’s apparently a Syrian refugée crisis in Europe. It’s unfortunate; but I won’t read about it. What good does it do? Nothing. So why bother reading about it? My sphere of interest should coincide with my sphere of influence. I feel bad about their situation; but all I can do it live my own life as simply as I can.

  2. Don’t click link bait. Ever. Do the world a favor and stop clicking link bait. Don’t click any title that begins with a number, e.g. “6 easy ways to make the most of working from home.” Don’t click any link with women in bikinis. These are rabbit holes from which you eventually emerge with self-loathing. And by clicking on link bait, you’re voting for crap on the web. Even some well-known newspapers like the Washington Post are full of link bait. Learn to recognize link bait and stop clicking it.

  3. Know what you want. Before you open a browser window, you exactly what you’re looking for. Find it, save it. Then close the window. Failure to know what you’re looking for on the web just makes you susceptible to what everyone else thinks you should look at. And 99.9% of it is crap.

  4. Stop social networking. Facebook, Twitter and whatever comes next are enormous wastes of mental energy. If after diving into Facebook only to emerge an hour later you feel the guilt and self-loathing of a heroin addict, you should. Facebook and its worthless spawn are the crack cocaine of the web.

  5. Use a crutch. “You can’t change what you don’t measure.” So measure your computer use. Get RescueTime and install it on your computer(s). It will give you reports on how much time you spend doing various tasks on the computer. Unfortunately, it doesn’t do much on the iPhone because Apple has iOS locked down. But on your laptop, desktop and Android devices you can get excellent data on what your spending your time doing at the computer.

  6. Put down your phone. Few things send me into more rage than seeing people walking around mesmerized by their little glowing rectangles. Seriously, what the hell is wrong with people? It’s not that interesting. Get a life.

  7. Train yourself to ignore advertisements. Block the hell out of advertisements. I’m completely unmoved by specious arguments about how unethical it is to block ads and how it will destroy the web as we know it. It’s not my fault that the web is monetized in screwy ways. I didn’t ask for valuable services to be free. Stop making yourself a target for advertiser’s Jedi mind tricks. Install an AdBlocker and aggressively block their psychomanipulations.

It’s much easier to have a quiet mind by making your forays into the web as transactional as possible.

Working with DEVONthink Pro Office and Hazel

My main organizational tool DEVONthink Pro Office, a tool I’ve used for many years. I’ve written previously about it and how I use it to find things and how I synchronize databases across machines.

I’m a relative newcomer to Hazel though. Hazel’s tagline is “automated organization for your Mac.” Hazel works as an agent to keep folders organized on the Mac. It’s an engine that applies per-folder rules to take actions on files and folders. Actions can include tagging files, moving them to other folders, running AppleScripts, deleting them, etc.

Since DEVONthink is the centerpiece of my organizational tools on the Mac, I wondered if Hazel and DEVONthink might be able to work together in a productive way. It’s an experiment that turned out well. I’ll describe two cases where I’m using them together. Read more after the break.

Read More

Iterated playlists in iTunes

iTunes doesn’t make it easy to build playlists with multiple iterations of the same track. You can do it; but with every addition iTunes puts up a dialog box and asks you if you indeed intent to do it. It’s an annoyance.

I wrote a short AppleScript that allows you to build a playlist built with multiple iterations of a group of selected tracks. The script allows you to specify the name of the playlist and how the tracks are to be added (all of the iterations of one track back-to-back [AAABBBCCC] or repetitions of each group of tracks. [ABCABCABC]) Read more after the break.

Read More

Recycling is a distraction

John Tierney, writing in the New York Times:

to reduce carbon emissions, you’ll accomplish a lot more by sorting paper and aluminum cans than by worrying about yogurt containers and half-eaten slices of pizza. Most people also assume that recycling plastic bottles must be doing lots for the planet. They’ve been encouraged by the Environmental Protection Agency, which assures the public that recycling plastic results in less carbon being released into the atmosphere.

But how much difference does it make? Here’s some perspective: To offset the greenhouse impact of one passenger’s round-trip flight between New York and London, you’d have to recycle roughly 40,000 plastic bottles, assuming you fly coach. If you sit in business- or first-class, where each passenger takes up more space, it could be more like 100,000.

Recycling many products, especially plastic and metal is enormously expensive and it does not necessarily offset the environmental effects of alternative means of handling the waste. Mostly it’s a distraction. It’s a form of absolution. Like the guy who builds an enormous mansion and slaps an array of photovoltaics on the roof. He will never recoup the energy expended in converting raw materials to building products and assembling them into a house.

Not consuming in the first place side-steps the issue entirely. We need to consume less. But since the “not consuming” lobby is non-existent we’ll never see structural solutions, only individual behaviors.

On not linking to Amazon

After reading a series of pieces including a recent article in the New York Times about the deplorable work conditions at Amazon, I’ve decided to make a policy against linking to Amazon.

It’s commonplace in the blogging work to link to Amazon when referencing books and other media so that readers can be sure of exactly which item the author is referring to. Effective today, I’m no longer providing links to products distributed by Amazon. Instead, I’ll endeavor to be as specific about authors and titles as I can.

While I am in awe of the diversity of products offered by the company and the speed with which it can deliver products, the costs are too great. Here are my concerns. TL;DR; - You should obtain books from your local public library.

What do I have against Amazon?

Privacy

In order to purchase anything from Amazon, you must identify yourself to the company. For this reason, they know about your reading habits. All of them. Eric Snowden has made it clear that the NSA is well aware of what anyone is reading by virtue of its connections to Amazon. In the same way that Facebook and other social media giants create robust sets of data about your life, dislikes and social connections, Amazon is creating an enormous knowledge base about your reading interests. If you are going to purchase books you should do so with cash and without identifying yourself.

Treatment of employees

Amazon is a bully. Not only with competitors, but with its own employees. Warehouse employees are know to labor under brutal physical conditions, subjected all the while to continual electronic surveillance lest they fail to meet their quota. The company has a system that is widely used by employees to sabotage one another. In so doing, it acts like a promoter of social Darwinism where only the most ruthless sociopaths can survive. By all accounts it is a horrible, dehumanizing place to work.

Purchasing most books is waste of resources

I suspect that most books are read 0-1 times. Therefore, private ownership of most books is a waste of resources. Shipping of small numbers of items long distances is a waste of fuel. Local production, distribution and consumption will reduce our dependence on fossil fuels and ultimately reduce the impact on the environment.

Economics

Both collective and personal economics are harmed by Amazon. The ease with which individuals can purchase books from Amazon encourages them to buy more. The recommendation engine built on top of the massive amount of data individuals unwittingly give up is designed for one purpose - to encourage you to buy more. In the collective, Amazon is known - like many big companies - to evade taxes.

What does Amazon care about books?

Amazon may have started as an online bookseller; but it has long since made itself into something much larger (and at the same time lesser…) Amazon is a product distributor. They are in the business of delivering physical stuff to you. It does not really concern itself with books per se except to the extent that they have economic value.

Monopolies are bad

Amazon is an undisputed monopoly in the product distribution business online. They operate in many of the same ways as the equally-unsavory WalMart. In the process of driving down prices on the consumer side, they squeeze margins upstream. It is not beyond the realm of possibility for Amazon to use its monopolistic power to fundamentally shape what gets written and published through “evidence-based” feedback loops.

Alternatives

Where possible you should obtain books from your local library. The local public library is one of the few remaining egalitarian institutions left in our society. When I visit our local library, I see persons of every socioeconomic group, every ethnic group. There are no distinction made between persons. We should support a place like this wholeheartedly.

Sure, Amazon offers instantaneous access to its titles via Kindle. But who cares? When was the last time someone suffered an ill effect of not having a book delivered to them within seconds of purchase? Our local library cooperates with numerous regional libraries to find books that are not in its collection.

See also

Why is the U.S. obsessed with home ownership?

If you’ve lived in the U.S. for any length of time, you realize that we have a national obsession with home ownership. Yet I’m beginning to wonder about this bit of American orthodoxy. I’ve owned 4 homes and none of them seemed like much of an investment to me. The last home that we sold was an enormous loss. We are now in a transition, anticipating our new move; so we are house-free (and debt-free!) So it’s an ideal time to unpack the complexities of home ownership.

Selected rates of home ownership worldwide

Rates of home ownership worldwide are not uniform; and these rates are not associated with most measures of individual and collective financial success. For example, the highest rate of home ownership is found in Romania, a country not known for its economic productivity. And the lowest rate of home ownership is among the Swiss, a people known for the financial-savvy.[1] In fact, the Swiss save almost 17% of their disposable income compared to about 5% in the United States. If we construct a relationship between per capita GDP and the rate of home ownership for the countries listed in the chart above, the linear correlation coefficient is 0.3112. In other words, there isn’t a relationship between home ownership and economic productivity.

In the U.S., the Federal bias is toward home ownership is both longstanding and questionable. Presumably, the Federal government has in interest in promoting asset accumulation among its citizens. But as Edward Glaeser has pointed out[2] one wonders why homes, among all the other forms of assets should be favored in this way. Hypothetically, the Fed could provide individuals with similar magnitude tax deduction for the purchase of stock. Since one of the most prominent ways that the Federal government subsidizes home ownership is through its mortgage interest deduction, the question of whether the mortgage interest deduction actually aids in asset accumulation is legitimate. Among the problems with the hypothetical connection between the mortgage interest deduction and wealth accumulation are:

  • The mortgage interest deduction disproportionately benefits wealth Americans. Analyses have shown that the relationship between household income and the tax savings from the mortgage interest deduction is non-linear.
  • The mortgage interest deduction encourages people to buy larger houses In an effort to take a larger deduction, people take out larger mortgages to pay for larger houses. There are important environmental and other reasons to discourage this trend.

Aside from the theoretical side, there are real economic findings that suggest home ownership may be an inefficient investment. From 1890 to 2005, when adjusted for inflation, home prices rose 103%, much lower than the rate of rise of the stock market. Since 1900, the U.S. stock market returned approximately 10% per year - about an order of magnitude more than home ownership. Yale economics professor Robert Shiller estimates that the ROI for U.S. home ownership is betweem 0 - 1%. As others have noted, 1% maintenance costs would mean an ROI of under 1%, perhaps even negative. Many other factors can lower this value further - including real estate transaction costs, property taxes, and homeowners association dues.

I’ve come to regard some of Americans’ love affair with home ownership as an anachronism. In the generation before mine, no one lived in HOA’s. People tended to work at the same job for their entire adult lives. And they tended to change houses much less often. All of these factors have changed in the ensuing generations. Yet the informal analyses that prospective buyers do are partly based on assumptions that derive from the “old days.”

In Canada, the analysis is simpler. Apart from buying leverage, there is no advantage to taking out a mortgage because there is no mortgage interest deduction.

Our housing plan

Our plan is based on the following considerations:

  • We will live below our means. I grew up in a family of 4 in an 1100 square foot home. We did fine. Massive swaths of granite, Cambria, and designer fixtures are for suckers. BMW’s, Mercedes, Land Rovers, and other “clown cars” are for suckers.[3] Lawns onto which people pour toxic chemicals and on which people waste millions of gallons of fresh water are for show. We are committed to leaving below our means.

  • We will decouple housing from employment. Houses are massive anchors. We encountered that when we were on the verge of building a massive house. Fortunately we recovered from our delusion. Here’s the deal. Obligations reduce the range of choices open to the obligor; and houses are enormous obligations. By living below our means, we will reduce the burden of our obligations and become independent enough to think about work on its own merit rather than according to the degree to which it allows to live in a certain house.

  • We will eliminate or minimize our mortgage. We are saving the overwhelming majority of our household income with a goal of paying cash for our next house. If a desirable house that fits our well-defined functional needs comes along before enough cash has accumulated, we will take out a mortgage for no more than $150,000 - one that we can easily pay off in 5 years or so.

  • We will be patient, slow, and deliberate. We’ve made bad real estate decisions. Our last house was massively over-priced. We failed to read the imminent bursting of the U.S. housing bubble. We failed to consider how nettlesome and expensive HOA’s are.[4] After selling our last house and living in a rental home, I’ve begun to realize just how easy it is to make more rational decisions by staying out of the market until everything is just right.

See also


  1. The story of homeownership in Switzerland is complex. The Swiss don’t actually prefer to rent. A 1996 survey revealed that 83% of Swiss would prefer to own their homes rather than rent. source. It turns out that Swiss tax policy makes home ownership very difficult because of imputed rent. Swiss home owners are taxed on an imputed income as if they had rented their home to another individual. Fortunately, such a scheme was deemed unconstitutional by the U.S. Supreme Court back in 1934. Helvering, Commissioner of Internal Revenue v. Independent Life Insurance Co.

  2. Glaeser, Edward L. 2011. Rethinking the Federal Bias Toward Homeownership. Cityscape: A Journal of Policy Development and Research 13(2): 5-37. Link

  3. In the interest of accurate disclosure, we were once suckers according to this standard. We’ve recovered; and the prognosis is good.

  4. Our last home was part of a HOA. The rules were irregularly enforced and there were simply not enough homes to support the ongoing maintenance costs. The cost of maintaining (and eventually replacing) the private paved road was a “ticking time bomb.”

3 months without a smartphone

Seeing the world without a filter
I wrote about my decision to give up my iPhone and how it felt one week later. Now I’ve had over three months without a smartphone.

First, I don’t regret the decision to give it up. I own the phone and have no contract. Most smartphones are purchased on contract so that you can properly compensate the carrier from whom you purchased the phone. Because we are planning to move out of the country sometime next year, I did not want to be forced to pay an early termination fee. Furthermore, I want to be a free-agent. If the carrier works for me, I’ll pay the monthly service fee. Otherwise I’m free to seek out another carrier.

The phone still won’t reliably connect to the Bluetooth hands-free system in my Prius V. If I want to use the phone hand-free, I have to power cycle it. Every time. It’s a huge nuisance.

The lack of a GPS is an occasional issue; but I have one in my car and when I’m traveling, I’m usually with someone who has a smartphone. I have no shame about leeching off their purchases!

Similarly, sometimes I just want to take a quick photo; but the camera on the dumbphone is grainy and doesn’t integrate with anything else that I use. No matter, someone can take the picture and email it to me.

Most importantly, I feel no compulsion to check email or any social media sites. When I have down-time, waiting in line at the store, I’m happy to watch and think.

Mostly, I feel more in-control. And the extra $60/month is not too bad, either.

The Art of Just Enough

!

In the popular sci-fi movie series “The Matrix”, a handful of humans discover that the perception of reality has been artificially engineered by computer software. By taking the red pill[1] a person can be released from the deception, thereby seeing things as they truly are. About material “stuff”, I’ve had the same sort of epiphany.

Three years ago, we decided we needed to build a house. We weren’t pleased with our previous neighborhood; and we happened on a piece of land that seemed to fit our needs. We began working with a builder to design a house. Despite our intent to build a smaller house, the design ended up being considerably larger than the house we were already in. Everything was to be custom-designed and fabricated. All of the fixtures were selected. We had spent hundreds of hours thinking about the designs, going to meetings, reading books, looking at photographs. It was an enormous investment of time and a significant investment of money.

Eventually, we had an epiphany. I couldn’t sleep and felt restless. We had been living with a constant sense of anxiety about the money, about the pace of the planning, and about the future house becoming an anchor. We stayed awake talking about it until nearly 1 AM. The next morning we called off the project.

Since then, we’ve sold our house and the land. We moved into a rental house that is a little crowded but is adequate for our needs. We’ve sold, given away, or discarded hundreds of unneeded items. The process of shedding all of this is like taking the “red pill”. It is hard to look at the ridiculous sums of money that people spend on their houses without feeling that we’ve all been trapped in a “Matrix” of misperceptions. We’ve been jacked-in to the mental games played by advertisers and the real-estate industry. Both operate by promoting the idea that you can be happier with more material goods. Your life isn’t going to be any better because you have Corian, or quartz, or granite, or whatever countertops. You won’t feel more at home because of your soaring ceilings. The phenomenon of hedonic adaptation[2] will ensure that you’ll need a stronger “dose” of material stuff when the pleasure of your luxury house wanes. And it will wane.

We’ve purposely put ourselves in a position to find the boundaries of what is enough. It’s surprisingly little.


  1. In “The Matrix”, the protagonist was offered the choice between a red pill and a blue pill. Taking the red pill would reveal stark reality. Taking the blue pill would continue the illusion.

  2. The hedonic treadmill, or hedonic adaptation is a mechanism whereby humans tend to return to a given set-point for happiness. Gregg Easterbrook has extended the idea of hedonic adaptation by observing the ways the people believe themselves to be deprived, the so-called “abundance denial”. He describes this well in The Progress Paradox: How Life Gets Better While People Feel Worse (Random House, 2003) available at your local library

What is southern pride anyway?

A recent poll surveyed attitudes of whites and African-Americans about their attitudes toward the Confederate battle flag. 61% of whites oppose measures to redesign state flags that feature Confederate emblems while 59% of African-Americans do.

When asked whether the Confederate battle flag symbolises southern pride or racism, 66% of whites believed that the flag was a symbol of southern pride whereas 77% African-Americans saw the flag as a symbol of racism.

As a person born in the southern part of the United States, I have a valid right to question the legitimacy of the Confederate battle flag as a proper symbol of anything good. Why is it even useful to call oneself a “Southerner” as if one’s place of origin has any utility? I’m from Louisiana. So what? Does that mean I love my family more? Less? The same?

Dear Confederate battle flag supporters: You may see the flag as some sort of pride; but it’s misplaced. It’s time to unpack the feeling of pride. What, exactly, are you proud of? Does it mean “I feel comfortable in my location of origin?” OK, so do people born in Reykjavik. Does it mean: “I love my family?” Right, so do the Belgians. Evolution has ensured that family units stick together. And consider for a minute why persons from other states don’t feel the need to fly a flag to proclaim their warm and fuzziness. Why do you need an ambiguous symbol to stand for pride? You want to be proud of something? Fix your public health crisis. Properly fund higher education. Fix your tax systems so you can support state infrastructure. Stop defunding early childhood development programs.

And stop flying that flag. Put in a museum.