View Single Post
There may be as many as 400 posts on these OmniFocus forums which contain technical tips or scripts which would work for directly-purchased copies of OmniFocus, but would not work on copies purchased through the Mac App Store.

[Estimate based on results from the 'advanced search' dialogue this morning: keyword:"com.omnigroup" forum: OmniFocus and child forums - show results as:post (447 posts, in over 280 different threads)]

There are also various OmniFocus scripts hosted on other sites which Mac App Store copies are similarly unable to run.

I suspect that neither Omni nor the user community can afford to spend the northern summer going through all these scripts and technical hints to edit even just the most useful ones into a shape that MAS-purchased copies can run.

In other words, first-aid for puzzled or disappointed users of app-store copies will mainly have to be DIY.

It may, therefore, be helpful to summarize the problem and the fixes.

The problem boils down to:
com.omnigroup.Omnifocus
vs
com.omnigroup.OmniFocus.MacAppStore
[For perfectly understandable reasons of internal house-keeping, Omni, unlike most other companies who sell through the Mac App Store, have chosen to give the App Store version a different 'bundle name'. Unfortunately, while this doesn't affect the performance of the software itself, it does prevent it from running a number of the useful scripts and command line hints that are published on this board and elsewhere]

Applescripts
If you find that your Mac App Store copy of OmniFocus can not run an OmniFocus Applescript, you may need to edit:
application id "com.omnigroup.omnifocus"

to any one of the following (it doesn't really matter which)
application id "OFOC"
application "OmniFocus"
application id "com.omnigroup.omnifocus.macappstore"

(NB the middle option doesn't use the "id" keyword)

If you are still getting messages about missing databases, you may need to edit:
~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2
to
~/Library/Caches/com.omnigroup.OmniFocus.MacAppStore/OmniFocusDatabase2
We should be able to find the correct path for the database file with more general code along the lines of:

Code:
property pTitle : "Coding for variant bundle identifiers"
property pstrDBPath : "$HOME/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2"

on run
	if not CacheFound() then return
	
	display dialog (do shell script "sqlite3 \"" & pstrDBPath & ¬
		"\" 'select count(*) from task where projectInfo is null and childrenCount = 0'") & ¬
		" tasks" buttons {"OK"} default button 1 with title pTitle
end run

on CacheFound()
	if (do shell script "test -e \"" & pstrDBPath & "\"; echo $?") ≠ "0" then
		try
			tell application "Finder" to tell (application file id "OFOC") to ¬
				set pstrDBPath to "$HOME/Library/Caches/" & its id & "/OmniFocusDatabase2"
		on error
			error "OmniFocus not installed..."
			return false
		end try
		if (do shell script "test -e \"" & pstrDBPath & "\"; echo $?") ≠ "0" then
			error "OmniFocus cache not found at " & return & pstrDBPath
			return false
		end if
	end if
	return true
end CacheFound

Note that you can also derive the currently installed bundle variant (in exchange for the more stable and ancestral 4 letter creator code) for other bifurcating Omni products, like OmniGraffle, OmniPlan, OmniOutliner, and OmniGraphSketcher:
Code:
property pTitle : "Bundle variants of installed Omni apps"
property plstName : {"OmniFocus", "OmniGraffle", "OmniPlan", "OmniOutliner", "OmniGraphSketcher"}
property plstCode : {"OFOC", "OGfl", "OPla", "OOut", "RSGS"}

set str to ""
tell application "Finder"
	repeat with i from 1 to length of plstCode
		try
			set str to (str & id of application file id (item i of plstCode) as string) & return
		on error
			set str to str & item i of plstName & " not installed" & return
		end try
	end repeat
	
	if button returned of (display dialog str buttons {"Esc", "Copy"} default button 2 with title pTitle) ≠ "Esc" then
		set the clipboard to str
	end if
end tell
[NOTE: the advantage of including the keyword file before id in the expressions above is that it avoids forcing the application to launch if it is not currently running. If the application is already running, or forcing it to launch is not a problem, then execution will be marginally faster if file is omitted]
Command Lines
Changing the path of the database file, as above, will also be the solution if you are having no luck with a tip for a Terminal command line that includes the keyword sqlite3

For example, to get a total count of tasks, (fine-tuning Ken Case's tip, to exclude the projects and action groups from the count) :
Code:
sqlite3 ~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2 'select count(*) from task where projectInfo is null and childrenCount=0'
would simply become:
Code:
sqlite3 ~/Library/Caches/com.omnigroup.OmniFocus.MacAppStore/OmniFocusDatabase2 'select count(*) from task where projectInfo is null and childrenCount=0'
Or, more generally, with two command lines:
Code:
OFOC=$(osascript -e 'tell application "Finder" to get id of application file id "OFOC"')
sqlite3 ~/Library/Caches/$OFOC/OmniFocusDatabase2 'select count(*) from task where projectInfo is null and childrenCount=0'


Finally, if you are having no luck with a tip or hint that involves a command line starting with something like:
defaults write
or
defaults delete
then, again, you need to change the domain from "com.omnigroup.Omnifocus" to "com.omnigroup.Omnifocus.MacAppStore"

To allow for uncertainty about which version is installed on a machine, and to defend against yet more proliferation of bundle variants, we would have to retreat from the elegance and brevity of Ken Case's tweetable command line of June 1 2011, to the relative verbosity and inconvenience of a more circumspect applescript:

Code:
DefaultsWrite("OFOC", "AppleHighlightColor", "1.0 0.0 0.0")

on DefaultsWrite(strCreator, strKey, strValue)
	tell application "Finder"
		try
			return do shell script ("defaults write " & id of application file id strCreator & ¬
				space & strKey & space & quoted form of strValue)
		on error
			return "Could not find an application with Creator code " & strCreator
		end try
	end tell
end DefaultsWrite
Try tweeting that ...

In the uncertain world of .MacAppStore and other variant bundle identifiers, restoring a default setting with defaults delete becomes equally verbose:

Code:
DefaultsDelete("OFOC", "AppleHighlightColor")

on DefaultsDelete(strCreator, strKey)
	tell application "Finder"
		try
			return do shell script ("defaults delete " & id of application file id strCreator & space & strKey)
		on error strMsg number errNum
			if errNum = -10814 then
				tell application id "sevs"
					activate
					display alert "No application found with creator code " & strCreator
				end tell
			else
				return ""
			end if
		end try
	end tell
end DefaultsDelete
Probably simpler to do it in the terminal. We can get the installed bundle identifier into a variable,

Code:
OFOC=$(osascript -e 'tell application "Finder" to get id of application file id "OFOC"')
and then use the variable to change settings,
Code:
defaults write $OFOC AppleHighlightColor "1.0 0.0 0.0"
or restore defaults.
Code:
defaults delete $OFOC AppleHighlightColor

Complex installation histories

Applications can be installed to the all-user /Applications folder, or the user-specific ~/Applications folder, or even, if history is getting little complex and messy, to both. We could even end up with different variants in different places ...

To check which .app file would actually be launched by an applescript, we can write something like:

Code:
-- e.g.
-- OFOC OmniFocus
-- OGfl OmniGraffle
-- OOut OmniOutliner
-- DNtp DEVONthink Pro
-- Scrv Scrivener
-- etc

AppPath("OFOC")

on AppPath(strCreatorCode)
	tell application "Finder" to tell (application file id strCreatorCode) to POSIX path of (its container as alias) & name
end AppPath


I may have overlooked some other issues, but at least this is a start ...
Good luck !

PS, a caveat:

I don't own an AppStore-bought copy myself, and thus haven't been able to test the remedies above, so to quote the immortal Dr Livesey, "look out for squalls ..."


--

Last edited by RobTrew; 2011-07-07 at 02:44 AM.. Reason: GetCachePath() improved, thanks to work by Ken Case