Script Executor for skEdit

This script is tied to the Shift-command-E key and will run the script in the front most window.
Send Snippet To: Save this snippet to Code Collector Pro -- view all jemstart's snippets
language: Python
license: Other

Code for Snippet:

#! /usr/bin/python
# - runs the text through the markdown processor
# The first line of the selected file needs to have some sort of execute statement
# -- PB User Script Info --
# %%%{PBXName=Execute Script}%%%
# %%%{PBXInput=AllText}%%%
# %%%{PBXOutput=SeparateWindow}%%%
# [email protected]}%%%		### Command-Shift-E
import os
import stat
import sys
filePath = "%%%{PBXFilePath}%%%"
## if the returned filePath is length 0
if len(filePath) == 0:
	## if you would like to write this to different path change it here
	filePath = "/tmp/skEdit_execute_tmp.txt"
	f = open( filePath, 'w' )
	f.write( """%%%{PBXAllText}%%%""" )
## At this point we have a file name
f = open(filePath, 'r')
ex =		## read the first 2 characters to check for the #!
if ex != "#!":
	print "Found '%s': File must start with a '#! <some path to exec>'" % ex
	## must set the either the real file or the tmp file to executable	
	st = os.stat(filePath)
	os.chmod(filePath, st.st_mode | stat.S_IEXEC)
	print "Successfully Executed: %s" % filePath
comments powered by Disqus


Tags: skEdit-Scripts nuggit-scripts python execute

Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 886
Date Added: 2013-07-20 18:41:32
Last Modified: 2014-10-24 16:51:39

Web Analytics