NeoLauncher Code

From NeoWiki

Jump to: navigation, search

xcode files:

-- neolauncher.applescript
-- neolauncher

--  Created by Jacob  Haddon on 9/19/06.
--  Copyright (c) 2006. Released under LGPL

on clicked theObject
	set j to (name of theObject as string)
	--display dialog j
	if j is equal to "open" then
		display open panel
		set the pathNames to (path names of open panel)
	else if j is equal to "quit" then
		quit {}
		openNeoOffice(j, "-")
	end if
end clicked

on run
end run

on open (theFiles)
end open

on idle
	-- close icon only if ooo has terminated
	if isOOoRunning() = 0 then
		tell me to quit
	end if
	-- check all x seconds if ok to quit
	return 3
end idle

on quit
	if isOOoRunning() = 0 then
		continue quit
		display dialog "NeoOffice is still running, are you sure you want to quit NeoLauncher?"
		continue quit
	end if
end quit


on isOOoRunning()
	set soffice to getProgramPath() & "/soffice"
	set isRunning to do shell script "_FOUND_=`ps -wx -o command | grep \"" & soffice & "\" | grep -v grep`; echo $_FOUND_"
	if isRunning ≠ "" then
		return 1
		return 0
	end if
end isOOoRunning

on openNeoOffice(progToOpen, aFile)
	set l to getProgramPath()
	--display dialog l
	--display dialog progToOpen
	do shell script ¬
	"alreadyRunning=`ps -auxww | grep soffice |grep -v grep | wc -l`;
	exec \"" & l & "/soffice.bin\" -" & progToOpen & " \"" & aFile & "\" &
	if [ $alreadyRunning -eq 1 ]
	osascript -e 'tell app \"NeoOffice\" to activate';
end openNeoOffice

on checkPath(aPath)
	set pathFound to do shell script "if [ -d \"" & aPath & "\" ]; then echo \"true\"; else echo \"false\"; fi"
	--display dialog quoted form of aPath
	if (pathFound = "true") then
		return 1
		return 0
	end if
end checkPath

-- getInstallPath
-- finds the path to the oo.o installation
-- checks the path to make sure there is something there
-- returns true if so, or error message if not

on getNeoPath()
	set myPath to (path to me)
	--set oooInstallPath to "/Applications/"
	tell application "Finder" to set j to POSIX path of (application file id "org.neooffice.neooffice" as string)
	set NeoInstallPath to j & "/Contents"
	if checkPath(NeoInstallPath) = 0 then
		display dialog "No valid installation found at: " & NeoInstallPath
		return ""
		return NeoInstallPath
	end if
end getNeoPath

on getProgramPath()
	return getNeoPath() & "/MacOS"
end getProgramPath

on openFiles(fileList)
	-- open dialog sends posix 
	if (count of fileList) > 0 then
		repeat with i from 1 to the count of fileList
			set theDocument to (item i of fileList)
			--display dialog theDocument
			openNeoOffice("soffice", theDocument)
		end repeat
	end if
end openFiles

Personal tools