iScripts- an Applescript Editor Assistant

Hi,
i’m glad to contribute with my first entry in Code exchange. Hello Scripters world!
I created this Helper-app with comfort-tools for Applescripters who miss some handy methods .get it, on the fly
You’ve to save the script code as stay-open application, add a nice icon and voila. You’re ready to go- try it for a while and enjoy using it. Bug reports are welcome.

####################################
A short introduction

The main target of iScripts is to deliver more comfort-tools as the original ‘Applescript editor’ offers.

Features:

¢ open dictionaries of running applications (i like it compact and minimal!)
¢ open scripting additions (osax) -(they’re useful and underrated) NOTE: Osax plugins are an older technology, therefore i cannot guarantee that these features and plugins are yet available in Mac OS Lion and higher
¢ open shell commands (manual pages) -(when applescript isn’t reliable and slow)

¢ create a new template with some basic structure to start off quickly (project your script!)
¢ create often used routines in the Applescript editor and collect these in your snippets folder to access them quickly- (txt is lightweight and easy to open and manipulate)
¢ insert txt- snippets

¢ merge multiple scripts in one (to build applications quickly)
¢ script projects = put important scripts in a project folder which you’re working on, to access them quickly (iScripts will save your scripts here: Home/Desktop/AppleScript Project/)

¢ call various applications aside iScripts, which aid you to code your scripts faster! these applications are only recommendations, and its up to you if you want to use these additional applications or not. The copyright of those applications goes to the respective owners.
¢ read Applescript reference books to build scripts with more speed. Code and learn to code better in the same time!
¢ Quit= close iScripts


to get iScripts working properly, you need to save it as stay-open application.
iScripts creates no more than three (3) support folders :

¢ one folder to store a list of Scripting Reference Books (Home/Documents/Scripting Ref/)
¢ snippets needs a folder (Home/Library/Application support/iScripts/Snippets/)
¢ scripts project creates a folder on the desktop (Home/Desktop/AppleScript Project/)


Workflow concept:

  1. Launch iScripts instead of ‘Applescript Editor’.
    ‘Applescript Editor’ will start

  2. code and consult Reference Books to:
    a) learn to code better
    b) understand for which environment you need to build your script (interdisciplinary reading)

  3. merge your code with other code
    a) to build a meaningful application, instead to have a million of little scripts around
    b) to create a whole, valorizing modest codes in a certain context. Scripts are like pages of a Book (Application)

  4. Create snippets
    a) they’re easy to create. Do it! no additional code is needed to insert those snippets into your code
    b) take a break ! scripting becomes fun, if your snippets base is well sorted and your work is done earlier with the help of snippets.

  5. launch other developer apps to get another view-point about scripting
    a) compare scripts in TextWrangler
    b) if you’re unable to proceed with Applescript, continue with Xcode

####################################

#iScripts
#Applescript editor
#0,804
#Developed by joy, 11.06.13, ->13.08.13
#=====================================
#HELP:
# some comfort-tools for applescripters
# additional, recommended software 
# -TextWrangler
# -UIElementInspector 
# -ASObjC Runner  
# 
# Installing:
# save this script as stay-open application, add a nice icon and voila. You're ready-try it for a while and enjoy.
#
# usage:
# this app continues to run silently and to save your scripts after launching. 
# Access options clicking on "iScripts" in the Dock
#
#=====================================
#iScripts is: -free software -use at your own risk
#Original code by joy for code exchange on macscripter.net, contact me at: http://gothicage.deviantart.com/
#=====================================

script help_txt
	property quick_desc : "iScripts helps you during the entire code development process assisting Apple's 'Applescript Editor', offering: " & return ¬
		& " . calling development applications, like: Applescript editor, Xcode, Text Wrangler, [[rate +20]] UI Element Inspector, [[rate -20]] AppleScript Object C Runner and Automator directly from iScripts ; " & return ¬
		& " . opens (script dictionaries) from supported files like, . extensions with suffix=o-si ax, . application dictionaries with suffix: es def, . shell script man pages; " & return ¬
		& " . open a list of the last modified scripts, . find and open documents using a certain variable, . see statistics for saved scripts  ; " & return ¬
		& " . create a new template and save your scripts or applications in a structured form; [[slnc +400]] " & return ¬
		& " . create code snippets and retrieve them easily; . search for code snippets on the web ; . merge scripts and build applications on the fly ; . customize Applescript Applications with icons of your choice ; . add and consult your scripting reference eBooks; " & return ¬
		& "last but not least; .you' re able to backup and upgrade your scripts using the option 'Versionize script', every time you consider your project being mature .for a next development step" & return ¬
		& " .iScripts requirements: ;  should work with all Mac Os X versions. ; Drag and drop . is supported for reference books, . Applescript editor scripts to access helper scripts quickly . and Applications who support your coding process; . Installing: ;  " & return ¬
		& " save this script as stay-open application, add a nice icon -and you're ready. .Make it a habit to click iScripts in your Dock at any time, to acquatain yourself with all the features of 'iScripts' can offer to boost your coding." & return ¬
		& "Try it for a while and [[rate +20]] ann- [[rate +20]] joy ! [[rate -40]]"
	
	property h_pr1 : "A folder with name [[rate +60]] 'AppleScript Projects'; [[rate -20]] has been created [[volm +0.2; rate -40]] on [[slnc +200]]your desktop [[slnc -200]]."
	property h_pr2 : "There, you'll find all your Skripts created with iScripts.  [[slnc +200]]."
end script

property del2 : "#====================================="
property title_txt : "#title" & return & "#tag" & return & "#version"
property iScripts_Author : "#Developed by "
property iScripts_license : "#-Free Software- use at your own risk" & return & "#Original code by joy for code exchange on macscripter.net, contact me at: [url=http://gothicage.deviantart.com/]http://gothicage.deviantart.com/"[/url]
property commt_txt : "#HELP: " & return & "# " & return & "# " & return & "#TODO: " & return & "# - " & return & "# - " & return & "# - "

property appsupp_fl : ((path to application support from user domain as text) & "iScripts:" as text)
property del : "_________________________"
property Documentation_list : {"pdf", "pages", "rtf", "rtfd", "txt", "doc", "docx", "csv", "xls", "textClipping", "epub"}
property def_kw : {"apps", "choose", "date", "dialog", "finder", "comments", "lists", "mail", "plugin", "property", "repeat", "replace", "shell", "text"}
property sub_c : {"Dictionaries.", "Templates.", "Support.", del, "Quick Scripts", "Versionize script", "Documentation", del, "Quit Session"}
property doc_pt : ""
property desk_pt : ""
property dev_pt : ""
property get_pt : ""
property del3 : 1.0E-3
global Appscr_app, full_nm

on run
	tell application "System Events" to set full_nm to name of current user
	my default_check()
	tell application Appscr_app to activate
	#my get_last_scripts()
end run

on idle
	tell application "System Events" to set all_titles to name of processes whose frontmost is true
	if Appscr_app is in all_titles then my save_file()
	#save automatically every 8 minuts
	return 8 * 60
end idle

on get_last_scripts()
	set nex to "*.scpt"
	#set here the days to check backward 
	set days_back to 21
	set proj_pt to do shell script "mdfind -onlyin '" & POSIX path of (path to home folder as text) & "' 'kMDItemFSName == \"" & nex & "\" && InRange(kMDItemContentModificationDate,$time.today(-" & days_back & "d),$time.today(+1d))'"
	
	if proj_pt is "" then
		my new_snipp()
	else
		set all_proj to number of paragraphs of proj_pt
		set nm_ls to {}
		repeat with a from 1 to all_proj
			set ppr to paragraph a of proj_pt
			if length of (a as text) = 1 then set a to "0" & a
			tell application "System Events" to copy (a & space & space & text 1 thru -6 of (get name of alias ppr) as text) to end of nm_ls
		end repeat
		
		activate
		set ch_from to choose from list nm_ls with prompt "latest modified Skripts - " & days_back & " days ago"
		if ch_from is false then
			tell application Appscr_app to activate
			return
		end if
		set ch_from to ch_from as text
		
		set target_scr to paragraph (word 1 of ch_from as text) of proj_pt
		do shell script "open '" & target_scr & "'"
	end if
	
end get_last_scripts


on default_check()
	--default values
	tell application "Finder" to set find_vrs to version
	if find_vrs < "10.6" then
		set Appscr_app to "Script Editor"
	else
		set Appscr_app to "AppleScript Editor"
	end if
	set {doc_pt, desk_pt} to {(path to documents folder as text), (path to desktop folder as text)}
	set dev_pt to POSIX path of (desk_pt & "AppleScript Projects:" as text)
	try
		do shell script "mkdir '" & dev_pt & "'"
		say help_txt's h_pr1 using "Alex"
		say help_txt's h_pr2 using "Victoria"
	end try
	
end default_check

on run_plugins()
	set comp_scripts to (appsupp_fl & "Plugins:" as text)
	do shell script "mkdir -p '" & POSIX path of comp_scripts & "'"
	set plugin_ls to list folder comp_scripts without invisibles
	
	if plugin_ls is {} then
		activate (display dialog "A Plugin-Folder has been created in \"Name/Library/Application Support/iScripts/\". Its a place for storing and executing your Applescript editor scripts" & return & "Drag and drop your favorite scripts onto iScripts, to collect them in its Plugins folder" with icon 1)
		return
	else
		set build_ls to {}
		repeat with a in plugin_ls
			copy text 1 thru -6 of a to end of build_ls
		end repeat
		activate
		set get_plugin to choose from list build_ls #default items (item 1 of sub_c)
		if get_plugin is false then return
		set get_plugin to get_plugin as text
		try
			run script file (comp_scripts & get_plugin & ".scpt" as text)
			tell application Appscr_app to activate
		on error
			beep
		end try
	end if
end run_plugins

on get_opt()
	#set open_doc to my save_file()
	#if open_doc is in true then return
	
	#if open_doc is in false then
	activate
	set ch to choose from list sub_c default items (item 1 of sub_c)
	if ch is false then
		tell application Appscr_app to activate
		return
	end if
	set ch to ch as text
	
	set ch_ls to ""
	if ch is "Dictionaries." then
		set ch_ls to {"Apps-Dictionary", "System-Dictionary", "Shell-Dictionary", del, "Last works", "Last Variables", "Statistics"}
	else if ch is "Templates." then
		set ch_ls to {"New Template", "Template from Selection", "Search Web-Snippet", del, "Insert Snippet", "Create Snippet", "Skripts Merge"}
	else if ch is "Support." then
		set ch_ls to {"TextWrangler", "ASObjC Runner", "UIElementInspector", "Xcode", "Automator", del, "Save App Icon", "Replace App Icon"} #MacHg, Smile, Script Debuggger, etc
	else if ch is "Quick Scripts" then
		my run_plugins()
		return
	else if ch is "Versionize script" then
		my versionize_scpts()
		return
	else if ch is "Documentation" then
		my open_books()
	else if ch is "Quit Session" then
		my quitme()
		return
	end if
	
	set ch to choose from list ch_ls default items (item 1 of ch_ls)
	if ch is not false then
		set ch to ch as text
		if ch is "Apps-Dictionary" then
			my open_dict()
		else if ch is "System-Dictionary" then
			my open_sys_dict()
		else if ch is "Shell-Dictionary" then
			my open_shell_dict()
		else if ch is "Template from Selection" then
			my partial_sel()
		else if ch is "New Template" then
			my new_snipp()
		else if ch is "Insert Snippet" then
			my get_snippet()
		else if ch is "Create Snippet" then
			my create_snippet()
		else if ch is "Skripts Merge" then
			my merge_scripts()
		else if ch is in {"TextWrangler", "ASObjC Runner", "UIElementInspector", "Xcode"} then
			my addt_apps(ch)
		else if ch is in "Statistics" then
			my open_stats()
		else if ch is in "Search Web-Snippet" then
			my get_websnippets()
		else if ch is "Last works" then
			my get_last_scripts()
		else if ch is "Last Variables" then
			my get_last_variables()
		else if ch is "Save App Icon" or ch is "Replace App Icon" then
			my save_replace_icon(ch)
		end if
	end if
	set {bl1, bl2} to {{"Documentation"}, {"TextWrangler", "ASObjC Runner", "UIElementInspector", "Xcode", "Automator"}} #"Shell-Dictionary", "Workflow Applications",
	--bring our Applescript editor back to front 
	if ch is not in bl1 and ch is not in bl2 or ch is false then tell application Appscr_app to activate
	#end if
end get_opt

on get_last_variables()
	#get current variable
	tell application Appscr_app to set cont to contents of selection of document 1
	
	#variables are varid for a day only
	set last_variables to (appsupp_fl & "Variables.txt" as text)
	tell application "System Events" to if exists alias last_variables then
		set cr_dt to short date string of (get creation date of alias last_variables)
		if short date string of (current date) ≠ cr_dt then delete alias last_variables
	end if
	
	#find variables
	set read_variables to ""
	try
		set read_variables to paragraphs 1 thru -2 of (read file last_variables)
	end try
	if read_variables is not "" then
		set read_variables to {"New Variable.", del} & read_variables
		activate
		set find_var to choose from list read_variables with prompt "Choose a Variable."
		if find_var is false then return
		set find_var to find_var as text
	else
		set find_var to "New Variable."
	end if
	
	if find_var is "New Variable." then
		activate
		set {theb, the_txt} to {button returned, text returned} of (display dialog "VARIABLES" & return & return & "List new variables." & return & del buttons {"Search", "Cancel"} default answer cont default button 2 with icon 1)
		
		tell application Appscr_app to activate
		if the_txt is not "" and theb is "Search" then
			#write variable
			set last_variables to (appsupp_fl & "Variables.txt" as text)
			set write_deleted to false
			try
				set control_vars to paragraphs of (read file last_variables)
				if the_txt is in control_vars then set write_deleted to true
			end try
			if write_deleted is false then my write_note(last_variables, (the_txt & return as text), false)
			
			#open documents with variable x
			my find_pos(the_txt)
		end if
		return
	end if
	
	set find_var to find_var as text
	#open documents with variable x
	my find_pos(find_var)
end get_last_variables

on find_pos(find_var)
	tell application Appscr_app
		set all_docs to name of documents
		set dd to 0
		repeat with a in all_docs
			if a does not end with "sdef" then
				set get_cont to contents of document a
				if find_var is in get_cont then
					open (get path of document a)
				end if
			end if
		end repeat
	end tell
	return
end find_pos

on save_replace_icon(my_cmd)
	#for apps only
	set {nm, get_pt} to {"", ""}
	try
		tell application Appscr_app to tell front document to set {nm, get_pt} to {name, path}
	on error
		return
	end try
	set get_pt to get_pt as text
	if nm does not end with ".app" then
		activate (display dialog "ERROR!" & return & return & "The frontmost item seems not to be an Application." buttons "End" default button 1 with icon 2)
		return
	end if
	set nm to (text 1 thru -5 of nm as text)
	set ppt to (get_pt & "/Contents/Resources/" as text)
	
	set icns_file to (ppt & "droplet.icns" as text)
	set def_pt to (path to pictures folder)
	
	tell application "System Events"
		if exists file icns_file then
			set icon_nm to "droplet.icns"
		else
			set icon_nm to "applet.icns"
		end if
	end tell
	set save_icon to (ppt & icon_nm as text)
	
	if my_cmd is "Replace App Icon" then
		#replace and update icon
		activate
		set ch_f to choose file default location def_pt with prompt "Choose an icon with suffix \".icns\""
		if (ch_f as text) does not end with ".icns" then return
		
		do shell script "cp -f -p '" & POSIX path of (ch_f as text) & "' '" & save_icon & "'"
		tell application Appscr_app to tell front document to save
		tell application "Finder" to update POSIX file (get_pt as text) as alias
	else
		#save icon
		set nmapp to POSIX path of ((path to desktop folder as text) & nm & ":" as text)
		do shell script "mkdir '" & nmapp & "'; cp '" & save_icon & "' '" & nmapp & icon_nm & "'"
	end if
end save_replace_icon

on open_stats()
	tell application Appscr_app to tell document 1 to set {lpp, cw, cch, nm, modf, pth} to {number of paragraphs, number of words, number of characters, name, modified, path} #, find_var, contents of selection
	
	if nm ends with ".app" then
		set pth to (pth & "/Contents/Resources/Scripts/main.scpt" as text)
	end if
	
	if pth is not in {Appscr_app, ""} then
		set {crdt, modt, daysbetw} to my file_info(pth)
		set add_line to return & del & return & "Created at: " & tab & tab & crdt & return & "Modified at: " & tab & tab & modt & return & "Amount of days: " & tab & daysbetw
		
		set long_dial to "STATISTICS" & return & ">" & nm & return & del & return & "Paragraphs: " & tab & lpp & return & "Words: " & tab & tab & cw & return & "Characters: " & tab & cch & add_line & return & del
	else
		set long_dial to "STATISTICS" & return & ">" & nm & return & del & return & "Paragraphs: " & tab & lpp & return & "Words: " & tab & tab & cw & return & "Characters: " & tab & cch & return & del
	end if
	activate
	display dialog long_dial buttons "Cancel" default button 1
	
	tell application Appscr_app to activate
	return
end open_stats

on file_info(f)
	set f to POSIX file f as alias
	tell application "System Events" to set {crdt, modt} to {creation date of f, modification date of f}
	set daysbetw to (modt - crdt) div 86400
	set {shcr, shmo} to {short date string of crdt, short date string of modt}
	return {shcr, shmo, daysbetw}
end file_info

on partial_sel()
	tell application Appscr_app
		tell front document
			set the selected_text to contents of selection
			if selected_text is "" then set selected_text to the contents
		end tell
		make new document with properties {contents:selected_text}
	end tell
end partial_sel

on save_file()
	with timeout of 30 seconds
		set {modif_, open_f, bk_up} to {false, false, false}
		set {nm, get_pt, hfs_dev_pt} to {"", "", POSIX file dev_pt}
		tell application Appscr_app
			#if number of documents = 0 then return #false
			tell document 1
				if name does not end with "sdef" then
					if modified is true and (number of paragraphs) > 5 and paragraph 5 is del2 & return then
						#mark as modified
						try
							set {nm_sc, get_pt} to {name, path}
						on error
							return
						end try
						set get_pt to get_pt as text
						tell application "System Events" to set short_crdt to short date string of (get creation date of alias get_pt)
						set short_dt to short date string of (current date)
						if short_crdt is not "" and short_crdt < short_dt then
							set modified_dt to ("#Developed by " & full_nm & ", " & short_crdt & ", ->" & short_dt & return as text)
							if paragraph 4 is not modified_dt then set paragraph 4 to modified_dt
							set bk_up to true
						end if
						
						set pp3 to paragraph 3
						if pp3 begins with "#version" then set paragraph 3 to "#0,001" & return
						
						if nm_sc ends with ".scpt" then
							set nex to ".scpt"
						else if nm_sc ends with ".app" then
							set nex to ".app"
						else
							#no valid file to save
							return # false
						end if
						
						set offs to offset of nex in nm_sc
						set scpt_tt to (text 1 thru (offs - 1) of nm_sc as text)
						set work_shop to (dev_pt & "@ " & scpt_tt & "/" as text)
						set create_scpt to (work_shop & scpt_tt & nex) as text
						do shell script "mkdir -p '" & POSIX path of work_shop & "'"
						
						if bk_up is true then
							do shell script "mkdir -p '" & (work_shop & "-Versions/" & "'" as text)
							#backup as text-file
							set mini_backup to (hfs_dev_pt & "@ " & scpt_tt & ":" & "-Versions:" & scpt_tt & "-New.txt" as text)
							my write_note(mini_backup, contents, true)
						end if
						
						set check_ls to list folder work_shop without invisibles
						if get_pt is not in work_shop and (scpt_tt & nex as text) is not in check_ls then
							--update contents
							do shell script "ln -s '" & get_pt & "' '" & work_shop & nm_sc & "'"
						end if
						save
						--dont bother with further options 
						#return true
					else
						return
					end if
				else
					return
				end if
			end tell
		end tell
	end timeout
end save_file

on open these_items
	--set applescript editor name, set user name
	my default_check()
	
	--get valid file extensions
	set {app_ls, ref_ls, plugin_ls} to {{}, {}, {}}
	tell application "Finder" to repeat with a in these_items
		set nex to name extension of a
		if nex is "app" then
			copy a to end of app_ls
		else if nex is "scpt" then
			copy a to end of plugin_ls
		else if nex is in Documentation_list then
			copy a to end of ref_ls
		end if
	end repeat
	
	#open application's script dictionary
	if app_ls is not {} then
		repeat with app_pt in app_ls
			set app_pt to app_pt as text
			--find sdef file first
			set get_dic to "mdfind -onlyin '" & POSIX path of (app_pt & "Contents:" as text) & "' -name .sdef "
			set sdef to do shell script get_dic
			
			if sdef is not "" then
				tell application Appscr_app to open paragraph 1 of sdef
			else
				try
					do shell script "open -a '" & Appscr_app & "' '" & POSIX path of app_pt & "'"
				end try
			end if
		end repeat
	end if
	
	#add new references to your Applescript Manual list
	if ref_ls is not {} then
		set Script_docs to (doc_pt & "Scripting Ref:" as text)
		try
			do shell script "mkdir -p '" & POSIX path of Script_docs & "'"
		end try
		try
			tell application "Finder" to move ref_ls to alias Script_docs
		end try
	end if
	
	#add favorite skripts as plugins to iScripts
	if plugin_ls is not {} then
		set Plugins_pt to (appsupp_fl & "Plugins:" as text)
		do shell script "mkdir -p '" & POSIX path of Plugins_pt & "'"
		try
			tell application "Finder" to move plugin_ls to alias Plugins_pt
		end try
	end if
	return
end open

on reopen
	my get_opt()
end reopen

on versionize_scpts()
	--0,001 better than 0,01
	set {modif_, open_f} to {false, false}
	set dev_hfs to POSIX file dev_pt
	tell application Appscr_app
		#if number of documents = 0 then return
		#please leave a minimum of 5 paragraphs to define your script's properties
		tell document 1
			if name does not end with "sdef" then
				if (number of paragraphs) > 5 and paragraph 5 is del2 & return then
					set build_new to false
					--accept scripts with structured concept table only
					set chars to {(character 1 of paragraph 1), (character 1 of paragraph 2), (character 1 of paragraph 3)}
					if chars is not {"#", "#", "#"} then return
					--versionize name
					set nm to name
					set short_dt to short date string of (current date)
					try
						set ppt to path
						tell application "System Events" to set short_crdt to short date string of (get creation date of alias ppt)
					on error
						set short_crdt to ""
					end try
					if short_crdt is not "" and short_crdt < short_dt then
						set modified_dt to ("#Developed by  " & full_nm & ", " & short_crdt & ", ->" & short_dt & return as text)
						if paragraph 4 is not modified_dt then set paragraph 4 to modified_dt
					end if
					
					if nm ends with ".scpt" then
						set nex to ".scpt"
						#set ftype to "osas"
					else if nm ends with ".app" then
						set nex to ".app"
						#set ftype to "APPL"
					else
						#build a new script 
						set nex to ".scpt"
						set build_new to true
					end if
					if build_new is false then
						set offs to offset of nex in nm
						set scpt_tt to (text 1 thru (offs - 1) of nm as text)
					else
						try
							set default_title to text 2 thru -2 of (get paragraph 1)
						on error
							set default_title to ""
						end try
						set scpt_tt to text returned of (display dialog "Name your script !" default answer default_title)
						if scpt_tt is "" then return
					end if
					
					set work_shop to (dev_pt & "@ " & scpt_tt & "/" as text)
					do shell script "mkdir -p '" & work_shop & "-Versions/'" #; mkdir -p '" & POSIX path of work_shop & "'"
					#tell application "Finder" to set dev_hfs to POSIX file work_shop
					
					set pp3 to paragraph 3
					set vrs to (characters 2 thru -2 of pp3 as text)
					if vrs is "version" then
						set vrs to "0,001"
					else
						set vrs to vrs + del3
						set vrs to vrs as text
					end if
					
					set paragraph 3 to ("#" & vrs & return as text)
					set {ch1, rest_ch} to {(character 1 of vrs as text), (text 3 thru -1 of vrs as text)}
					
					set create_vrs to (work_shop & "-Versions/" & scpt_tt & " " & ch1 & "." & rest_ch & ".txt" as text)
					set create_scpt to (work_shop & scpt_tt & nex) as text
					set check_ls to list folder work_shop without invisibles
					
					if build_new is false then
						set pt_doc to path
						if pt_doc does not start with work_shop and (scpt_tt & nex as text) is not in check_ls then
							do shell script "ln -s '" & pt_doc & "' '" & work_shop & "'"
						end if
						
						save
					else
						set create_scpt to (work_shop & scpt_tt & ".scpt" as text)
						save in create_scpt as "osas"
					end if
					my write_note((create_vrs as text), contents, false)
					set modif_ to true
				end if
			end if
		end tell
		if build_new is true then save document 1 in create_scpt
		
		if open_f is true then
			open create_scpt
		else
			activate
		end if
	end tell
	return modif_
end versionize_scpts

on quitme()
	tell application Appscr_app to quit
	set other_apps to {"TextWrangler", "ASObjC Runner", "UIElementInspector", "Xcode", "Automator"}
	repeat with a in other_apps
		set unix_id to ""
		try
			tell application "System Events" to set unix_id to unix id of process a
		end try
		if unix_id is not "" then quit application a
	end repeat
	quit me
end quitme

on addt_apps(ch)
	if ch is "TextWrangler" then
		--get selections or entire document from applescript editor
		tell application Appscr_app to tell document 1
			if contents of selection is "" then
				set scr_cont to contents
			else
				set scr_cont to (get contents of selection)
			end if
			set script_nm to name
			set scr_cont to scr_cont as text
		end tell
		tell application "TextWrangler"
			activate
			set mydocument to make new document with properties {name:script_nm, contents:scr_cont}
		end tell
	else
		set cmd to "open -a '" & ch & "'"
		try
			do shell script cmd
		on error notfound
			activate
			display dialog notfound with icon 2 buttons "Continue" default button 1
		end try
	end if
	tell application Appscr_app to activate
	
	return
end addt_apps

on open_books()
	--scripting reference path
	set Script_docs to (doc_pt & "Scripting Ref:" as text)
	try
		do shell script "mkdir -p '" & POSIX path of Script_docs & "'"
	end try
	set lf to list folder Script_docs without invisibles
	set more_options to {"Quick Help", "visit Macscripter", "visit Joy's Art gallery"}
	if lf is {} then
		set lf to lf & "New." & del & more_options
	else
		set lf to lf & del & "New." & del & more_options
	end if
	set chbk to choose from list lf with prompt "Choose Applescript Reference Book." default items (item 1 of lf)
	if chbk is false then return
	set chbk to chbk as text
	
	if chbk is "New." then
		try
			set chbooks to choose file default location alias desk_pt with prompt "Choose Applescript Books."
		on error
			tell application Appscr_app to activate
			return
		end try
		try
			tell application "Finder" to move chbooks to alias Script_docs
		end try
	else if chbk is "Quick Help" then
		say help_txt's quick_desc using "Alex"
	else if chbk is "visit Macscripter" then
		set the_URL to "http://macscripter.net/index.php"
		my visit_web(the_URL)
	else if chbk is "visit Joy's Art gallery" then
		set the_URL to "http://gothicage.deviantart.com/gallery/"
		my visit_web(the_URL)
	else
		set chfl to (Script_docs & chbk as text)
		try
			do shell script "open '" & POSIX path of chfl & "'"
		end try
	end if
	tell application Appscr_app to activate
	return
end open_books

on visit_web(the_URL)
	set res to check_net()
	if res is true then
		--open website with default browser
		try
			open URL the_URL
		end try
	else
		activate
		display dialog "This feature needs an active Network connection! Cancelling." with icon 2 buttons "End" default button 1
		return
	end if
	return
end visit_web

on open_shell_dict()
	--get main man pages
	--/usr/bin -->shell bins
	set the_pt to "/usr/share/man"
	do shell script "mkdir -p '" & POSIX path of appsupp_fl & "'"
	set rewrite to true
	set shell_dict to ""
	
	--find Shell Dictionary.txt
	set inputFile to (appsupp_fl & "Shell Dictionary.txt" as text)
	set lf to list folder appsupp_fl
	if "Shell Dictionary.txt" is in lf then
		set rewrite to false
		set shell_dict to paragraphs 1 thru -2 of (read file inputFile)
		set shell_dict to tagSort(shell_dict)
	end if
	
	set shell_dict to shell_dict & "."
	if shell_dict is not "." then
		set search_str to choose from list shell_dict with prompt "Searching for" default items (".")
		if search_str is false then return
	else
		set search_str to "."
	end if
	
	if search_str is in "." then
		set search_str to the text returned of (display dialog "Searching for" default answer "ssh")
	end if
	
	--test if the shell command exists
	if (number of words of search_str) > 1 then set search_str to (word 1 of search_str)
	set test_cmd to ("man -t '" & the_pt & "' '" & search_str & "'")
	set res to do shell script test_cmd
	
	--write to personal shell index
	if res is not "" then
		set comp_cmd to (test_cmd & " | open -f -a preview")
		do shell script comp_cmd
		if search_str is not in shell_dict then
			set search_str to (search_str & return as text)
			my write_note(inputFile, search_str, rewrite)
		end if
	end if
	return
end open_shell_dict

on open_dict()
	tell application "System Events"
		set visible_apps to name of processes whose background only is false and has scripting terminology is true
		set invisible_apps to name of processes whose background only is true and has scripting terminology is true
		if "ASObjC Runner" is in invisible_apps then copy "ASObjC Runner" to end of visible_apps
	end tell
	
	activate
	set frontApp to choose from list visible_apps & del & "Choose application." with prompt "Choose application"
	if frontApp is false or frontApp is in del then return
	set frontApp to frontApp as text
	if frontApp is "Choose application." then
		set posix_pt to "/Applications/"
		try
			set get_app to choose file default location posix_pt with prompt frontApp
			do shell script "open -a '" & Appscr_app & "' '" & POSIX path of get_app & "'"
		on error number the err
			if err is -128 then return
		end try
	else
		try
			tell application "System Events" to set frontApp to application process frontApp
		end try
		
		--Open a choosen script dictionary.
		tell application Appscr_app
			try
				open file of frontApp as alias
			on error
				try
					open file of application frontApp
				end try
			end try
		end tell
	end if
	return
end open_dict

on open_sys_dict()
	set addition_sdef to {"StandardAdditions", "URL Access Scripting", "Keychain Scripting"}
	set hidden_sdef to {"Image Events", "System Events", "Database Events", "Automator Runner", "AppleScript Runner"}
	set more_sdef to {"Printer Setup Utility", "HelpViewer", "VoiceOver", "SpeechRecognitionServer"}
	
	activate
	set frontApp to choose from list addition_sdef & del & hidden_sdef & del & more_sdef with prompt "Choose Scripting osax"
	if frontApp is false then return
	set frontApp to frontApp as text
	
	if frontApp is in hidden_sdef or frontApp is in addition_sdef or frontApp is in more_sdef then
		if frontApp is in addition_sdef then
			if frontApp is "StandardAdditions" then
				set frontApp to frontApp & ".osax"
			else
				set frontApp to frontApp & ".app"
			end if
			set frontApp to POSIX file ("/System/Library/ScriptingAdditions/" & frontApp) as text
		else
			if frontApp is "SpeechRecognitionServer" then
				
				set frontApp to POSIX file (do shell script "mdfind -onlyin '" & POSIX path of (path to library folder from system domain as text) & "' -name SpeechRecognitionServer") as text
			else
				set frontApp to POSIX file ("/System/Library/CoreServices/" & frontApp & ".app") as text
			end if
		end if
	end if
	--Open a choosen dictionary.
	tell application Appscr_app
		activate
		try
			open file of frontApp as alias
		on error
			open alias frontApp
		end try
	end tell
	return
end open_sys_dict

on get_snippet()
	--create snippets rep
	set snipp_pt to (appsupp_fl & "Snippets:" as text)
	try
		do shell script "mkdir -p '" & POSIX path of snipp_pt & "'"
	end try
	--link to snippets rep
	if (list folder snipp_pt without invisibles) is {} then
		activate
		display dialog "NO SNIPPETS FOUND !" & return & return & "Choose \"Create Snippet\" in \"iScripts\" to use this feature !" & return & "Search \"Macscripter\" for Code Snippets:" buttons {"Macscripter", "Abbruch"} default button 2 with icon 2
		set btn to the button returned of the result
		if btn is "Macscripter" then my get_websnippets()
		return
	else
		--choose and insert a snippet
		activate
		set ch to choose file default location alias snipp_pt with prompt "Choose your snippet"
		if ch is false then return
		set ch to ch as text
		set read_cont to read file ch
		
		tell application Appscr_app to tell document 1
			activate
			set contents of selection to read_cont
			delay 0.2
			try
				compile
			end try
		end tell
		return
	end if
end get_snippet

on get_websnippets()
	set res to check_net()
	if res is true then
		try
			open URL "http://macscripter.net/index.php"
		end try
	else
		activate (display dialog "NO NETWORK CONNECTION" & return & return & "This function needs an active Network connection. End." with icon 2 buttons "End" default button 1)
		return
	end if
end get_websnippets

on create_snippet()
	--create snippet-path
	set snipp_pt to (appsupp_fl & "Snippets:" as text)
	try
		do shell script "mkdir -p '" & POSIX path of snipp_pt & "'"
	on error
		activate
		display dialog "The default location for saving your snippets seems bocked. We are unable to create our snippets folder." & return & return & "Please correct the access privileges of folder \"Application Support\" if you are the admin -look at the bottom of the info panel-  i'll open the info panel for you, now" buttons "Continue"
		tell application "Finder" to open information window of (path to application support from user domain)
		return
	end try
	
	tell application Appscr_app
		activate
		set the get_code to contents of selection
		if get_code is "" then set the get_code to contents of document 1
	end tell
	
	#insert keywords
	set tag_file to (appsupp_fl & "Keywords.txt" as text)
	try
		set read_kwords to read file tag_file
		set kw_ls to {}
		set nr_ppr to (number of paragraphs of read_kwords) - 1 #last paragraph is empty
		repeat with a from 1 to nr_ppr
			set ppr to paragraph a of read_kwords
			if ppr is not "" then copy ppr to end of kw_ls
		end repeat
		set def_kw to def_kw & del & kw_ls
	end try
	
	#choose keyword
	repeat
		activate
		set get_kw to choose from list def_kw & del & "New Keyword." with prompt "Choose a Keyword for your Snippet"
		if get_kw is not false and (get_kw as text) is not in del then exit repeat
	end repeat
	set get_kw to get_kw as text
	#log get_kw
	
	if get_kw is "New Keyword." then
		activate
		set new_kw to text returned of (display dialog get_kw default answer "" with icon 1)
		if new_kw is false or (new_kw as text) is "" then return
		set get_kw to new_kw as text
		
		if get_kw is not in paragraphs of (read file tag_file) then my write_note(tag_file, (get_kw & return as text), false)
	end if
	##insert keywords
	
	try
		activate
		set name_snip to (choose file name default location alias snipp_pt default name "Title") as text
	on error number the err
		if err is -128 then return
	end try
	set lg_name to (length of name_snip) - (length of snipp_pt)
	set orig_nm to (text -1 thru -(lg_name) of name_snip)
	
	#write code snippet
	set create_snip to (snipp_pt & get_kw & "-" & orig_nm & ".txt" as text)
	set res to my write_note(create_snip, get_code, false)
	if res is false then
		activate
		display dialog "Your snippet could not be saved. Please correct the access privileges of your snippet-path !" & return & return & "I'll open the info window for you, now" buttons "Continue"
		tell application "Finder" to open information window of alias snipp_pt
	end if
	return
end create_snippet

on new_snipp()
	--insert template paragraphs, technical specifications and basic handlers
	tell application "System Events"
		set visible_apps to name of processes whose background only is false and has scripting terminology is true
		set invisible_apps to name of processes whose background only is true and has scripting terminology is true
		if "ASObjC Runner" is in invisible_apps then copy "ASObjC Runner" to end of visible_apps
	end tell
	
	activate
	set frontApp to choose from list visible_apps & del & "Choose application."
	if frontApp is false then
		tell application Appscr_app to activate
		return
	end if
	set frontApp to frontApp as text
	if frontApp is "Choose application." then
		set posix_pt to "/Applications/"
		set get_app to choose file default location posix_pt with prompt "Search application"
		tell application "System Events" to set frontApp to name of get_app
	end if
	tell application "System Events"
		try
			tell process frontApp to if has scripting terminology is false then set frontApp to "System Events"
		on error
			activate
			set get_app to get_app as text
			tell application "Finder" to set plistFile to POSIX path of (get_app & "Contents:" & "Info.plist" as text)
			try
				tell application "System Events" to tell property list file plistFile
					set icon_v to (value of property list item "CFBundleIconFile") as text
				end tell
				if icon_v does not end with ".icns" then set icon_v to icon_v & ".icns"
				--display dialog icon_v
				set icon_pt to alias (get_app & "Contents:Resources:" & icon_v as text)
			on error
				set icon_pt to 2
			end try
			
			display dialog "APPLICATION REFUSED" & return & return & "'" & frontApp & "' seems not to support Applescript." with icon icon_pt buttons {"Continue", "Cancel"} default button 1
			set the_b to the button returned of the result
			if the_b is "Cancel" then return
			
			set frontApp to "System Events"
		end try
	end tell
	
	set crdt to (short date string of (current date))
	set base_scr to "property a : \"\"" & return & "property b : \"\"" & return & "property c : \"\"" & return & return & return & "tell app \"" & frontApp & "\"" & return & return & "end tell" & return & return & "on main()" & return & return & "return" & return & "end main" & return #System Events
	#set temp_synt to title_txt & return & iScripts_Author & crdt & return & del2 & return & commt_txt & return & del2 & return & iScripts_license & return & del2 & return & return & base_scr & return & return
	set temp_synt to title_txt & return & iScripts_Author & full_nm & ", " & crdt & return & del2 & return & commt_txt & return & del2 & return & return & base_scr & return & return
	
	tell application Appscr_app
		activate
		--create further documents up to the default document
		make new document
		--wait till the default window opens, starting session
		delay 0.2
		tell document 1
			set contents to (temp_synt as text)
			set paragraph 2 to "" & return
			set paragraph 2 to ("#" & frontApp as text) & return
			compile
		end tell
	end tell
	
	set scpt_nm to "untitled"
	repeat
		activate
		try
			set scpt_nm to text returned of (display dialog "Choose a name!" & return & "Illegal charakters ':'" default answer "untitled" with icon 1)
			if ":" is not in scpt_nm then exit repeat
		on error
			exit repeat
		end try
	end repeat
	if scpt_nm is in {"", "untitled"} then
		tell application Appscr_app to activate
		return
	end if
	--create a simple projects folder (no nested folders needed)
	set cmd to "mkdir -p '" & dev_pt & "@ " & scpt_nm & "/-Versions/'"
	try
		do shell script cmd
	end try
	
	set create_scpt to (dev_pt & "@ " & scpt_nm & "/" & scpt_nm & ".scpt") as text
	tell application Appscr_app
		tell document 1
			set {paragraph 1, paragraph 3} to {"#" & scpt_nm & return, "#version" & return}
			--first, save your original file
			save in create_scpt as "osas"
			--create a backup copy to work with
		end tell
		--link front document to its path
		save document 1 in create_scpt
	end tell
	return
end new_snipp

on merge_scripts()
	--pack scripts as routine scripts in one document
	set {mem, the_nms} to {{}, ""}
	set dd to 0
	try
		tell application "Finder" to set frfl to (folder of front window as text)
	on error
		set frfl to desk_pt
	end try
	set sel to choose file default location alias frfl with prompt "Merge Scripts in a bigger One" & return & "Choose multiple files holding the \"Shift\" key" of type "osas" with multiple selections allowed
	set cc to number of items of sel
	
	repeat with ptme in sel
		set dd to dd + 1
		set ptme to ptme as text
		tell application "System Events" to set nm to (name of alias ptme)
		set chrs to 1
		if character 1 of nm is " " then set chrs to 2
		set lgex to 1
		set offs to (offset of "." in nm)
		if offs ≠ 0 then set lgex to length of (get text (offs - 1) thru -1 of nm as text)
		
		set nm to (text chrs thru -lgex of nm as text)
		set htxt to paragraphs of (do shell script "osadecompile " & quoted form of POSIX path of ptme)
		set nfr to {}
		repeat with a in htxt
			copy a & return to end of nfr
		end repeat
		set nfr to nfr as text
		set mem to mem & ("script v_" & dd & return & nfr & return & "end" & return & return)
		if dd = cc then
			set the_nms to (the_nms & "\"" & nm & "\"" as text)
		else
			set the_nms to (the_nms & "\"" & nm & "\"" & "," as text)
		end if
	end repeat
	
	--create new app
	set dt_today to (short date string of (current date))
	set first_ln to "set the_ls to {" & the_nms & "}" & return & "set option_v to choose from list the_ls with prompt \"Choose from stack\" with multiple selections allowed" & return & "if option_v is false then return 0" & return & "set option_v to option_v as text" & return & return
	
	set call_str to {}
	repeat with i from 1 to number of items in sel
		if call_str is {} then
			copy "if option_v is item " & i & " of the_ls then" & return & "run script v_" & i & return to end of call_str
		else
			copy "else if option_v is item " & i & " of the_ls then" & return & "run script v_" & i & return to end of call_str
		end if
	end repeat
	copy "end" & return & return to end of call_str
	
	tell application Appscr_app
		make new document without properties
		--insert template paragraphs, technical specifications and basic handlers
		set crdt to (short date string of (current date))
		set temp_synt to title_txt & return & iScripts_Author & full_nm & ", " & crdt & return & del2 & return & commt_txt & return & del2 & return & return
		set merge_it to temp_synt & return & first_ln & call_str & mem
		set contents of front document to merge_it as string
		try
			compile front document
		end try
	end tell
	activate
	repeat
		set scpt_nm to text returned of (display dialog "Choose a name!" & return & "Illegal Characters ':'" default answer "untitled" with icon 1)
		if ":" is not in scpt_nm then exit repeat
	end repeat
	if scpt_nm is "" then return
	
	--you save scripts as an application not for development, but for use 
	set create_scpt to POSIX path of ((path to desktop folder as text) & scpt_nm & ".app" as text)
	tell application Appscr_app
		tell document 1
			set {paragraph 1, paragraph 3} to {"#" & scpt_nm & return, "#1,0" & return}
			try
				save in create_scpt as "APPL"
				close without saving
				set was_saved to true
			on error the_err
				beep
				set was_saved to false
			end try
		end tell
		if was_saved is true then open create_scpt
	end tell
	if was_saved is true then
		activate
		display dialog "Add a nicer Icon to your new Application ?" buttons {"Yes", "No"} default button 1 with icon 1
		set the btn to the button returned of the result
		if the btn is "Yes" then my save_replace_icon("Replace App Icon")
		
		tell application "Finder" to reveal alias (POSIX file create_scpt as text)
	else
		display dialog "ERROR" & return & "Your Application could'nt be built" & return & the_err buttons "End" default button 1 with icon 2
	end if
	return
end merge_scripts

on write_note(inputFile, to_write, rewrite)
	set res to true
	try
		set accessRef to open for access file the inputFile with write permission
		
		if rewrite is true then
			set eof accessRef to 0
			write to_write to accessRef #as «class utf8»
		else
			write to_write to accessRef starting at eof #as «class utf8»
		end if
		close access accessRef
		#close access file the inputFile
	on error
		set res to false
	end try
	return res
end write_note

--various Autors, from MACSCRIPTER
-----------------------------------------------------------------------------------
on check_net()
	try
		set the_URL to "http://www.google.com" as URL
		set dotted_ to dotted decimal form of host of the_URL --> this will return the IP address if there is a live connection 
		return true
	on error
		return false
	end try
end check_net

to tagSort(L) -- a general purpose simple sort; not enough tags to get fancy.
	considering case
		set sl to {}
		set IL to {}
		repeat (count L) times
			set the low_item to ""
			repeat with i from 1 to (count L)
				if i is not in the IL then
					set this_item to item i of L as text
					if the low_item is "" then
						set the low_item to this_item
						set the low_item_index to i
					else if this_item comes before the low_item then
						set the low_item to this_item
						set the low_item_index to i
					end if
				end if
			end repeat
			set the end of sl to the low_item
			set the end of the IL to the low_item_index
		end repeat
	end considering
	return sl
end tagSort


Last edited by Joy (2012-08-06)
v 0.17
i added some new features. new!
added a merge function to create Applications from Applescripts on the fly
added more script definition dictionaries
script export function for TextWrangler
restyled script description plan-now with your name signature

Last edited by Joy (2012-08-18)
v 0.2

new!
-added a personal shell script index
-corrected a little bug, which hindered the creation of some support-folders
-added a switch to ASObjC Runner, developed by Shane Stanley
-added a ‘Script Projects’ feature to collect important scripts as alias in a folder on the desktop

Could you edit your first post to tell us what this does? I’d like to know if it will be useful for me without reading the (quite long) code. Thanks.

Last edited by Joy (2012-08-22)
v 0.23

new
-now you’re able to save your Applescript Editor’s frontmost document as a snippet
a) as a whole by selecting nothing
b) a portion of it, by selecting the wanted lines
-some tweaks and corrections

Last edited by Joy (2012-09-29)
New! version 0.28
⁃ ability to organize and read Applescript References eBooks
⁃ drag and drop to get application dictionaries and to Reference eBooks
⁃ concept table simplified for the versioning feature
⁃ search for snippets on Macscripter
⁃ some improvements
⁃ removed a lot. of little bugs

I think this is the last entry here. The app works well here on Snow Leopard - if you run into errors, try to study the code in Script editor. I’m open for suggestions and bug reports if you need. Thanks for using iScripts.

Last edited by Joy (2012-10-02)

inspired by MacUsr on article http://macscripter.net/viewtopic.php?id=39561, I updated ‘iScripts’ for the very last time. I tested every function and command of the code more than once, so everything should work.
(Nobody is perfect, so my slowness to finish this code)

New features in version 0.29
⁃ now every script is saved in its own project folder inside ‘Script Projects’ on the desktop
⁃ now you’re able to backup and upgrade your script every time you managed to solve inherent bugs and features, prior to move on for the next development step.
⁃ ability to choose dictionaries from non-running application as well
⁃ added a quick help in ‘Documentation’ who tells you briefly the main features of iScripts
⁃ search snippets at Macscripter
⁃ abc sorting for your personal shell dictionary searches

I hope iScripts is a nice addition and foremost, practical app for your scripting needs.
best wishes and happy coding
Jo

Last edited by Joy (2012-10-04)
edit:
⁃ resolved some weak code lines
⁃ improved save process (if you miss to save your template, you’ll get the opportunity to save your file later as well)

Last edited by Joy (2013-02-13)

Hi,
I released a minor upgrade to fix:
⁃ now the versionize feature works like expected - changes are linked back to the original file in the ˜Finder’
⁃ now iScripts helps you to re-locate your code back to the default ‘workshop’ folder
⁃ some interface cleanup to increase productivity

ps.don’t forget to save the code as a stay-open application and add a nice icon.

Last edited by Joy (2013-05-19)

I’m not tired to improve my little iScripts; in fact, it has become for me a useful companion together with the “Applescript Editor”. For those who checked my script “on the front page” only:
as you can see, i improved and rasped on many aspect, continuing to add or remove features to get a useful app, easy and intuitive to use for everybody. Because scripting is fun.

Updating:
⁃ replacing a feature, who moved applescripts back to its workshop, now iScripts makes an alias for moved scripts
⁃ Now you’re able to start a new template calling an application of your choice
⁃ ability to open your last modified scripts
⁃ minor code-clean up

cheers!

Last edited by Joy (2013-06-11)

Hi there,
and sorry for bothering another time. I think thats the very last time i update iScripts for the public domain. :smiley: :lol:
yes, i did more out of iScripts. I’m delighted to announce a major update. version 0.8 !

New features include:

  • basic statistical information for saved scripts/apps
  • templates from selection/ if nothing was selected, you’ll get a copy from the entire script code
  • search the web for code snippets
  • ability to save and replace icons for Applescript Applications
  • ability to execute Applescript editor related Scripts within iScripts - they are like plugins, add them via drag and drop onto iScripts
  • Versionize scripts now saves unsaved scripts too
  • now, saving happens silently in the background, every 8 Minutes and for the frontmost document
  • Quit Session replaces Quit, this means : now iScripts will quit together with Applescript Editor. Do a manual Quit of iScripts (cmd+q) if you want to leave Applescript editor running. Sincerely, i see no reason to quit iScripts before Applescript editor, but for the sake of choice.
  • bug squeezing

Requirements for iScripts 0.8

an Icons-Library (“.icns”) to assign nice icons to your applications