Miscellanous scripts

Hello

For those of you fortunate enough to have such a new version of OS X that your Library aren’t indexed by spotlight anymore, please do try this:

do shell script " mdimport ~/Library"

I have gotten that line from Technical Q&A QA1475: Tips for searching Headers, APIs and ADC reference material.

But it should work equally well for stuff stored in the Library folder. :slight_smile:

The Document just mentioned, puts the scripts in the posts above in a whole new light, making them less necessary, once you have read and adapted to the Q&A, but there should still be some use for them.

Here is a script for importing the headerr file for you for good measure (from 1475), I believe that you from Snow Leopard onwards then can write name: stdio.h for instance, in the Spotligt bar. :wink:

do shell script "mdimport /usr/include
mdimport /usr/local/include
mdimport /System/Library/Frameworks"

And while I am at it, here are two snippets for turning Airport on and off:

do shell script "networksetup -setairportpower en1 on"

I knew you’d guess it but:

do shell script "networksetup -setairportpower en1 off"

:slight_smile:

Hello.

Here are some links to some quicklook plugins that makes the script above work as they used to before Mavericks.

sindresorhus/quick-look-plugins

QuickLook Plugins List

There is is also an AppleScript Quick look plugin out there that works, as an aside. The one I use is named ScriptQL.qlgenerator

The path to the header files are now changed to:

(Thanks to Shane Stanley.)

This is for the mdimport you’ll probably have to do manually by the commands in the post right above.

Hello.

Should you have the need to debug quicklook, as it stops to work, then start looking for plugins that are in either /Library/QuickLook and ~/Library/QuickLook, and has a modification date back to 2007 . :wink:

Hello.

This is script that installs a git repo for an Xcode 5 project when either you are upgrading the project to Xcode 5, or forgot/refused to install a git repo in the first place.

You should stand on the root folder of the project in a Finder window, and execute the script from there. The folder structure of the Xcode project should be willy nilly, with a folder within the root folder of the project that carries the same name.

The script is kindof a state machine. It works as it should, but may be hard to modify.

You may want to modify it slightly if you are running Xcode 3 or Xcode 4 alongside Xcode 5.

global theLoc

set situ to 1
installGitRepo(situ)
on installGitRepo(situ)
	global theLoc
	tell application "Finder"
		try
			if situ = 1 then
				set theSel to selection
				if theSel is {} then error number 3000
				set theKind to class of item 1 of theSel
				if theKind is not folder then error number 3000
				set didSelect to false
			else
				set theSel to {}
				set end of theSel to choose folder default location theLoc with prompt "Select Xcode root folder."
				set didSelect to true
			end if
			
			set theName to name of item 1 of theSel
			if not didSelect and not (exists folder theName of (item 1 of theSel)) then error number 3001
			set pxPath to quoted form of POSIX path of (item 1 of theSel as alias)
			set repoExists to (do shell script "cd " & pxPath & "; test -d .git && echo \"true\" || echo \"false\"") as boolean
			if repoExists then
				display alert "A git repository is already in place"
				if situ = 2 then set target of Finder window 1 to item 1 of theSel
				set situ to -1
			else
				--every thing so far is okay time to create the git repo.
				set pxPath to quoted form of POSIX path of (item 1 of theSel as alias)
				
				do shell script "cd " & pxPath & " ; mkdir .git ; cat \"UserInterfaceState.xcuserstate
build
*.pbxuser
*.perspectivev3
*.mode1v3
*~
*~.nib
*~.xib 
.DS_Store 
xcuserdata/\" >.git/.gitignore;git init; git add .; git commit -m \"initial commit\""
				display alert "Successfully created .git repo for Xcode Project " & theName
				if situ = 2 then set target of Finder window 1 to item 1 of theSel
				set situ to 0
			end if
		on error e number n
			if n = -128 then
				set situ to -3
			else if n < 3000 then
				display alert "Unrecoverable error: 
" & e
				set situ to -2
			else if n = 3000 then
				set theTarget to name of its target of Finder window 1 -- as alias as text
				display alert "No folder selected in " & theTarget
				set situ to 2
			else if n = 3001 then
				set theFolder to name of item 1 of theSel
				display alert "No folder of folder " & theFolder & " named " & theFolder & ".
The folder can't be the root folder of an Xcode project."
				set situ to 2
			end if
		end try
		if situ > 0 then set theLoc to target of Finder window 1 as alias
	end tell
	
	if situ > 0 then
		installGitRepo(situ)
	else
		if situ = 0 then
			set theLoc to missing value
			if running of application "Xcode" is true then
				tell application "Finder" to display alert "You must restart Xcode to make it acknowledge the repo."
			else
				tell application "Finder" to display alert "You can start Xcode to use source control."
			end if
		else if situ = -1 then
			tell application "Finder" to display dialog "Do you want to create a repo for another folder?" with icon note
			set situ to 1
			installGitRepo(situ)
		end if
	end if
end installGitRepo


Hello.

I updated the script above, so that if the folder structure deviates from having subfolder with the same name, then you are allowed to use the same root folder, whence you select the folder the second time around, which you are forced to.

I am a fan of this script, since it lets me play with other peoples examples/code, without fear of not being able to go back to the original, and also without the hassle of having several copies of the same project, and the hurdles of figuring out which is which.