More improvements on TextMate’s ‘Apache Runner’

The RunPHP script in the previous post only checked to see whether XAMPP’s control app (‘Manager-osx’) was already running before sending the document’s URL to Safari. Firstly this Manager app has to be started manually with admin privileges, and then Apache and MySQL have to be maunaully started from within it.

However, as you can bypass Manager-osx and start both Xampp and MySQL automatically from a shell script such as:


do shell script "/Applications/xampp/xamppfiles/xampp start" password "password" with administrator privileges 

then any checking of the RunPHP script needs to be done against the Apache server rather than the Manager-osx app.

Here’s the modified RunPHP script


--RunPHP.scpt  
--create a <named>.php file in the php folder of xamppfiles/htdocs  and start XAMPP and the Apache server.
--Edit your <named>.php file, and test it by invoking this script (RunPHP) from the 'Apache Run' command in 
--TextMate's PHP (bundle) menu. Don't forget that the 'Apache Run' Command has to point to the location of this script 


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

global theName, myCount, theCount, docName, docPath, theURL, theResult

tell application "TextMate"
	get name of window 1
	set theName to the result
	
end tell

tell me
	set myCount to count characters in theName
	set mynameOffset to offset of "—" in theName
	set docName to (text 1 thru (mynameOffset - 1) of theName)
	set mydocOffset to mynameOffset + 2
	set docPath to (text mydocOffset thru myCount of theName)
	
end tell

--check whether Apache is running
set theResult to do shell script "/Applications/xampp/xamppfiles/xampp status"

set AppleScript's text item delimiters to "
"
set thelist to every text item of theResult
if item 2 of thelist ≠ "Apache is running." then
	display dialog "Please start Apache"
else
	set theURL to "http://127.0.0.1/" & docPath & "/" & docName as text
	tell application "Safari"
		make new document at front with properties {URL:theURL}
		activate
	end tell
	
end if

set AppleScript's text item delimiters to ""