Skip to content

APKManager.app source

Majick Tek edited this page Jul 26, 2017 · 8 revisions

Source to APKManager.app

So, in an attempt to make sure people don't somehow screw up the APKManager.app file (because honestly, its something I'd probably wind up doing myself) I've saved the applet 'run only' from within AppleScript Editor.

This now uses a simple 'c' script to read key codes, and allows the user to force reset their home directory selection by holing down the "command" key at launch. All credit for the c script belongs to Craig Williams, care of the apple mailing list post here: http://lists.apple.com/archives/applescript-users/2009/Sep/msg00374.html

The source file I used to compile "keys" is verbatim from that message, but nonetheless can be downloaded here.

However, I understand this can be distressing for some people, so here is the source-code for the applet, try it out yourself if you want!

to getApkmFolder()
	set tempFolder to choose folder with prompt "APK Manager OSX -- Please select the location of the main \"apkmanager\" folder"
	set tempTwo to get (POSIX path of tempFolder)
	set apkmFolder to do shell script "dirname \"" & tempTwo & "other\""
	do shell script "defaults write com.girlintroverted.apkmanager maindir \"" & apkmFolder & "\""
end getApkmFolder

to resetApkmFolder()
	do shell script "defaults write \"" & prefFileName & "\" maindir ERROR"
end resetApkmFolder

to checkOptionKey()
	try
		set mpath to get (path to me)
		set ppath to get (POSIX path of mpath)
		set startupKey to (do shell script "cd " & ppath & ";./Contents/MacOS/keys cmd")
		if startupKey is "1" then
			do shell script ("defaults write com.girlintroverted.apkmanager maindir ERROR")
		end if
	end try
end checkOptionKey

to makeExecutable(mainDir)
	try
		do shell script "chmod -R ug+x \"" & mainDir & "\""
	on error
		do shell script "defaults write com.girlintroverted.apkmanager maindir ERROR"
		display dialog "APK Manager encountered an error trying make directory executable, pleeas try again."
	end try
end makeExecutable

to runApkm(mainDir)
	tell application "Terminal"
		try
			activate
			set newTab to do script ""
			set number of columns of newTab to 100
			set number of rows of newTab to 39
			set title displays shell path of newTab to false
			set title displays device name of newTab to false
			set title displays custom title of newTab to true
			set custom title of newTab to "APK Manager"
			do script "/bin/sh -c exec test $(command -v apkm) && apkm && exit || \"" & mainDir & "/other/main.sh\" && exit" in newTab
		on error
			do shell script "defaults write com.girlintroverted.apkmanager maindir ERROR"
			display dialog "APK Manager encountered an error trying to launch the shell script, please try again."
			do script "exit" in newTab
		end try
	end tell
end runApkm

to setMainDir()
	set mainDir to do shell script "defaults read com.girlintroverted.apkmanager maindir"
	return mainDir
end setMainDir

on run
	set prefFolderPath to path to preferences folder as text
	set prefFileName to "com.girlintroverted.apkmanager.plist"
	set prefFilePath to prefFolderPath & prefFileName
	repeat
		try
			get prefFilePath as alias
			set plistExist to "true"
		on error
			set plistExist to "false"
		end try
		if plistExist is "false" then
			getApkmFolder()
		else
			if plistExist is "true" then
				try
					checkOptionKey()
				end try
				try
					set mainDir to setMainDir()
					if mainDir is "ERROR" then
						getApkmFolder()
						set mainDir to setMainDir()
					end if
					makeExecutable(mainDir)
					runApkm(mainDir)
				on error
					getApkmFolder()
					set mainDir to setMainDir()
					makeExecutable(mainDir)
					runApkm(mainDir)
				end try
				exit repeat
			end if
		end if
	end repeat
end run
Clone this wiki locally