Contextual Environment

Hi,

please read on if you’re interested in a better application launcher experience. Sounds boring ?

background
Apple sells us an Os with some standard tools, but they cover only a small part of our needs. Basically, everybody of us uses contexts of applications, some applications of a particular workflow category, like: 2d, 3d, writer tools, backup tools, ect.
With the time we start to accumulate applications to satisfy particular needs too. Therefore, wherever we look: Apps and more apps - we get lost in this flood of applications. Enough with all those apps !

A solution
Some software is completely useless - like the launchpad - apart the eye candy entertainment. Spotlight is fast, but needs filter methods. Too much folders in the Finder’s sidebar or Dock create unnecessary clutter.
So i thought to write a self-duplicating Applescript-Application ‘wrapper’, to call some context-specific applications defined by the user.

Usage

  1. Save the script below as an Application with name ‘Wrapper Util’. Don’t use another name, its important. Location isn’t crucial.
  2. Put your App ‘Wrapper Util’ in the Dock
  3. Start ‘Wrapper Util’, and follow the dialogs - create a context for ONE group of applications, some examples: 2d, 3d, backup, ect.
  4. You’ll find a new application on the desktop with its name related to the -context- specified before. Drag and Drop a a group of applications who belong to this particular context, onto this context app, NOT on “Wrapper utils”
  5. The Context app now creates some alias reference files here : Home/Application Support/Contextual_apps/YourContext/
  6. Continue to drop applications on the wrapper app, until you’ve added all the necessary apps of your particular context
  7. Now start using your Applescript context-App and choose the applications you want to launch! easier than that !
  8. if you need another context, launch ‘Wrapper Util’ again , see point 3)

ps
a) i suggest you to add meaningful icons to your Contextual applications, so you know which context you are launching. See the web for icon resources (*.icns)
b) create as much contexts as you need, but i’d suggest to keep the number of contexts low, to produce less clutter in your dock-bar.

i know, its a simple app, but its also intuitive and useful for everyday tasks. Less is often More!
Try my app and tell me your opinion !

#Wrapper Util
#Finder
#0,004
#Developed by Joy, 18.09.14
#=====================================
#HELP: 
# Launch application environments, effortless, at the push of a button
# 
#TODO: 
# - 
# -
#=====================================


on open these_apps
	#add more apps to the contextual env
	my main(these_apps)
	quit
end open

on run
	my main({})
end run

on main(these_apps)
	#main path
	set pt_me to ((path to me) as text)
	set appsupp to (path to application support folder from user domain as text) & "Context_Apps:"
	tell application "System Events" to set nm to name of alias pt_me
	
	if nm is "Wrapper Util.app" then
		#orig wrapper; create a copy to desktop
		set desk_pt to (path to desktop folder as text)
		
		#choose a name for your context-apps
		activate
		set {txt, btn} to {text returned, button returned} of (display dialog "Create a new context" & return & "" with icon 1 buttons {"Continue", "Uninstall", "Cancel"} default button 1 default answer "")
		if btn is "Cancel" or txt is "" then return
		
		if btn is "Uninstall" then
			tell application "System Events" to delete alias appsupp
			activate
			display dialog "Move \"Wrapper Util.app\" to the trash now." with icon 1 default button 2
			
		else
			#create a new wrapper
			set wrapper_pt to POSIX path of (desk_pt & txt & ".app" as text)
			do shell script "cp -rf '" & POSIX path of text 1 thru -2 of pt_me & "' '" & wrapper_pt & "'"
		end if
		
		#show the new wrapper
		tell application "Finder" to reveal POSIX file wrapper_pt as alias
		quit me
	else
		set context_fl to text 1 thru -5 of nm
		#contextual app
		set get_cont to appsupp & context_fl & ":"
		try
			set al_file to alias get_cont
		on error
			do shell script "mkdir -p '" & POSIX path of get_cont & "'"
		end try
		
		if these_apps is {} then
			set ls to list folder get_cont without invisibles
			if ls is {} then
				activate
				display dialog "Drag & Drop Applications of the following context: '" & context_fl & "'" with icon 1 buttons "Cancel" default button 1
				set the_b to the button returned of the result
				if the_b is in "Cancel" then quit me
				
			else
				tell application "System Events"
					set nmpproc to name of processes whose background only is false and name is not "droplet" and name is not "applet"
					set running_apps to {}
					repeat with a in ls
						if a ends with ".app" then
							set get_app to text 1 thru -5 of a
						else
							set get_app to a
						end if
						if get_app is in nmpproc then
							copy get_app to end of running_apps
						end if
					end repeat
				end tell
				if running_apps is not {} then
					activate
					display dialog "START oder QUIT Applications ?" with icon 1 buttons {"Start", "Quit", "Cancel"}
					set the_b to the button returned of the result
					if the_b is "Start" then
						my start_apps(get_cont)
					else if the_b is "Quit" then
						my quit_apps(running_apps)
					else
						return
					end if
				else
					my start_apps(get_cont)
					
				end if
			end if
		else if these_apps is not {} then
			#create alias refs, but only unique ones
			set lf to list folder get_cont without invisibles
			tell application "Finder" to repeat with a in these_apps
				if name of a is not in lf then
					set label index of a to 7
					make new alias file of alias get_cont to a
				end if
			end repeat
		end if
	end if
	
	return
end main

on quit_apps(running_apps)
	activate
	set ch to choose from list running_apps with prompt "Quit Applications..." with multiple selections allowed
	if ch is false then return
	
	set dd to 0
	repeat with a in ch
		set a to a as text
		quit application a
	end repeat
	return
end quit_apps

on start_apps(get_cont)
	#run normally, add apps by drag-drop
	activate
	set ch to choose file default location alias get_cont with prompt "Choose Applications..." with multiple selections allowed #of type "APPL"
	if ch is false then return
	
	repeat with a in ch
		set a to a as text
		tell application "System Events" to set nm to name of alias a
		try
			tell application a to activate
		on error
			set cmd to ("mdfind -onlyin /Applications/ '" & nm & "'" as text)
			
			try
				set keywd to paragraph 1 of (do shell script cmd) as text
			on error
				tell application "System Events" to delete ch
				return
			end try
			do shell script "open -a '" & keywd & "'"
		end try
		do shell script "sleep 0.5"
	end repeat
end start_apps