summaryrefslogtreecommitdiff
path: root/Utility/OSX.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-26 16:50:04 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-26 16:50:04 -0400
commitc9f341bd303a2d7b58eb0a7f6b596b7b1d7948bd (patch)
tree4f9097afb1cb69f1ba9653f6a90cb26ad0ddc090 /Utility/OSX.hs
parentcb1913e6cddfa090bda8b860d9b4129d83cf2c83 (diff)
make the standalone OSX app automatically install itself when run
Diffstat (limited to 'Utility/OSX.hs')
-rw-r--r--Utility/OSX.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/Utility/OSX.hs b/Utility/OSX.hs
new file mode 100644
index 000000000..e5c0b6266
--- /dev/null
+++ b/Utility/OSX.hs
@@ -0,0 +1,43 @@
+{- OSX stuff
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Utility.OSX where
+
+import Utility.Path
+
+import System.FilePath
+
+autoStartBase :: String -> FilePath
+autoStartBase label = "Library" </> "LaunchAgents" </> label ++ ".plist"
+
+systemAutoStart :: String -> FilePath
+systemAutoStart label = "/" </> autoStartBase label
+
+userAutoStart :: String -> IO FilePath
+userAutoStart label = do
+ home <- myHomeDir
+ return $ home </> autoStartBase label
+
+{- Generates an OSX autostart plist file with a given label, command, and
+ - params to run at boot or login. -}
+genOSXAutoStartFile :: String -> String -> [String] -> String
+genOSXAutoStartFile label command params = unlines
+ [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ , "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
+ , "<plist version=\"1.0\">"
+ , "<dict>"
+ , "<key>Label</key>"
+ , "<string>" ++ label ++ "</string>"
+ , "<key>ProgramArguments</key>"
+ , "<array>"
+ , unlines $ map (\v -> "<string>" ++ v ++ "</string>") (command:params)
+ , "</array>"
+ , "<key>RunAtLoad</key>"
+ , "</dict>"
+ , "</plist>"
+ ]
+