3 ms·
Editor: BBEdit. Cmd+B is hooked to the following AppleScript for my project: tell application "BBEdit" save front document end tell te
by chime 15y ago
Editor: BBEdit. Cmd+B is hooked to the following AppleScript for my project:
tell application "BBEdit"
save front document
end tell
tell application "Terminal"
if (count of windows) is 0 then
do script "/path.to.my/make.command"
else
do script "/path.to.my/make.command" in window 1
end if
end tell
tell application "Google Chrome"
activate
end tell
My make.command (simplified):
#!/bin/sh
coffee -c mycode.coffee
lessc -x mycode.less > mycode.css
rsync -avz --delete --force --exclude ".DS*"
-e "ssh my.ppk" /localpath/www user@me.com:/remotepath/www
On my server, I run a changed.php file:
function fileHash($fn) {
echo sprintf("%u.", crc32(file_get_contents(dirname(__FILE__) . $fn)));
}
header('Access-Control-Allow-Origin: *');
fileHash('mycode.js');
fileHash('mycode.css');
On all my HTML pages, I run this piece of CoffeeScript (compiled above to JS):
# defined elsewhhere:
# debugmode (bool)
# reloadIfChangedLast (empty string)
# getCurrentView() returns #pageHashURL
reloadIfChanged = ->
if not debugmode
return false
$.ajax
type: 'GET'
url: 'me.com/changed.php?rnd=' + Math.random()
error: ->
setTimeout reloadIfChanged, 500
return
success: (data) ->
if reloadIfChangedLast and data and
reloadIfChangedLast isnt data
reloadIfChangedLast = data
document.location.href = 'index.html?rnd=' +
Math.random() +
'#' + getCurrentView()
else
if data
reloadIfChangedLast = data
setTimeout reloadIfChanged, 500
return
return
It may seem like a lot of hassle but for me it's just copy-paste and edit a few things per project. And the benefits are tremendous.
- GeneralMaximus 15y agoBrilliant. AppleScript is underrated as an automation language. Sure, it's a bit cumbersome to write, but nobody says you have to use it for everything. It plays well enough with shell scripts that you can leave the heavy lifting to another language and use AppleScript as a bridge between the command line and the UI. Me and a friend once wrote a bot in Python to control various music players from IRC. The bot uses AppleScript to talk to iTunes on OS X, and GObject introspection (or whatever they use on GNOME these days; I have little experience with desktop Linux) to talk to Rhythmbox. See http://github.com/GeneralMaximus/amazing-horse http://github.com/GeneralMaximus/amazing-horse All of Apple's official applications support scripting, so do most good third party apps. You don't need extra JS on your page to autorefresh Safari. This little snipped reloads the front-most Safari tab: tell application "Safari" set sameURL to URL of tab 1 of front window set URL of tab 1 of front window to sameURL end tell You can even send Safari a snippet of JS to run. It's possible to automate any UI interaction by sending mouse clicks or keyboard events to tell application "System Events". You can look at any app's AppleScript dictionary using the AppleScript Editor. Go File -> Open AppleScript Dictionary ... and then pick your app.
- anthonyb 15y agoI do a similar thing in bash for more normal development - basically a script to run my unit tests, look for OK/Error in the output and print either a couple of bars in green or the error output in red. It runs over and over again in a separate monitor, so as soon as you have wrong code, you know about it.