2012-09-26 20:50:04 +00:00
|
|
|
{- OSX stuff
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-09-26 20:50:04 +00:00
|
|
|
-
|
2014-05-10 14:01:27 +00:00
|
|
|
- License: BSD-2-clause
|
2012-09-26 20:50:04 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Utility.OSX where
|
|
|
|
|
2012-10-29 17:12:39 +00:00
|
|
|
import Utility.UserInfo
|
2012-09-26 20:50:04 +00:00
|
|
|
|
|
|
|
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>"
|
2012-11-15 05:01:54 +00:00
|
|
|
, "<true/>"
|
2012-09-26 20:50:04 +00:00
|
|
|
, "</dict>"
|
|
|
|
, "</plist>"
|
|
|
|
]
|
|
|
|
|