The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus 1 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

FAQ: Enabling App-Store versions to use existing scripts and hints Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
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:
[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]

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:
We should be able to find the correct path for the database file with more general code along the lines of:

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
			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:
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
			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) :
sqlite3 ~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2 'select count(*) from task where projectInfo is null and childrenCount=0'
would simply become:
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:
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
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:

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

on DefaultsWrite(strCreator, strKey, strValue)
	tell application "Finder"
			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:

DefaultsDelete("OFOC", "AppleHighlightColor")

on DefaultsDelete(strCreator, strKey)
	tell application "Finder"
			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"
					display alert "No application found with creator code " & strCreator
				end tell
				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,

OFOC=$(osascript -e 'tell application "Finder" to get id of application file id "OFOC"')
and then use the variable to change settings,
defaults write $OFOC AppleHighlightColor "1.0 0.0 0.0"
or restore defaults.
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:

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


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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re-writing scripts for new Omni versions RobTrew OmniFocus Extras 0 2013-03-28 03:37 AM
can't move pre-existing project in to pre-existing folder kbs1138 OmniFocus 1 for Mac 3 2011-06-16 10:22 AM
Toolbar scripts don't store properties ptone OmniFocus Extras 1 2008-01-12 07:59 PM
OmniWeb Versions (Builds = Versions?) JAB Creations OmniWeb General 11 2007-07-03 05:32 AM
Using graphic objects as stencil items? (+ 2 hints) epo OmniGraffle Extras 0 2006-08-18 01:47 AM

All times are GMT -8. The time now is 11:31 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.