From: Tim Streater on 22 Nov 2009 17:57 On 22/11/2009 22:09, Rowland McDonnell wrote: [snip] > For me, the problem is that there seem to be no good learning resources > for *ANY* scripting language or indeed any programming language I can > find out about on Macs. Have you tried PHP? That has a large set of APIs to all sorts of things, a reasonable C-like syntax, easy string handling, and a very good website where the docs appear to be written in an adult fashion (unlike perl). I use no other. -- Tim "That excessive bail ought not to be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted" Bill of Rights 1689
From: Woody on 22 Nov 2009 19:19 Rowland McDonnell <real-address-in-sig(a)flur.bltigibbet.invalid> wrote: > Bruce Horrocks <07.013(a)scorecrow.com> wrote: > > > Rowland McDonnell wrote: > > > R <me32(a)privacy.net> wrote: > > > > > >> Rowland McDonnell <real-address-in-sig(a)flur.bltigibbet.invalid> wrote: > > >> > > >>> Isn't that the thinking behind *everything* on Macs these days? > > >>> > > >>> Apple provides stuff for numpties and for the Gods - the rest of us can > > >>> go hang. > > >> If it did not already exist, would Apple invent AppleScript today? > > > > > > Christ knows. AppleScript is appalling. > > > > > > But - well, I'd like to learn to program my Mac using *SOMETHING* so > > > that I can perform simple automated jobs like I could on my BBC Micro > > > back in the early 1980s. I've got this super Mac, but in some ways a > > > BBC Micro is more use to me- simply because a Mac won't let me automate > > > it. > > > > What sort of jobs? > > Hmm. I've given up thinking about automation since it's nearly > impossible to do any more - decades of `improvements' and that's one > thing which is definitely worse. > > So... Let's see. I can think of two jobs I do manually a lot which are > really annoying. > > I'd like a script that'd dive down a directory tree recursively and move > all files matching a specific pattern to the trash. > > (Job to be done: delete all *.log, *.aux, *.toc, *.lot, *lof, etc files > if they are in a directory with a *.tex file of the same filename root) That one should be pretty simple in any of the scripting languages such as python or php, or even non scripting languages such as java on the mac. I am sure it is probably simple in some of the shell languages or built in commands for those who know them (I say probably, as I don't do the unix scripting languages). I would have thought python would have a large number of online manuals for it as it is getting a lot of use in universities and the like - some of them must be up to standard. > And one to open a pdf file in Preview, change page size/orientation to > DL envelope/landscape, identify which pages in the pdf file have a paper > size matching DL envelope (job made easier by the fact that they're all > at the end - and I'd not mind typing in a single number if the machine > couldn't work that bit out), print 'em out using single sided best > quality printing (defined by a preset), and then put page > size/orientation back to A4 portrait. That sounds like an applescript thing. Never managed to get anything useful out of applescript. -- Woody www.alienrat.com
From: Bruce Horrocks on 22 Nov 2009 19:54 Rowland McDonnell wrote: > Bruce Horrocks <07.013(a)scorecrow.com> wrote: >> What sort of jobs? > > Hmm. I've given up thinking about automation since it's nearly > impossible to do any more - decades of `improvements' and that's one > thing which is definitely worse. > > So... Let's see. I can think of two jobs I do manually a lot which are > really annoying. > > I'd like a script that'd dive down a directory tree recursively and move > all files matching a specific pattern to the trash. > > > (Job to be done: delete all *.log, *.aux, *.toc, *.lot, *lof, etc files > if they are in a directory with a *.tex file of the same filename root) Here's a Bash shell script version: ---begin--- : for T in `find $1 -name "*.tex" -print` do for E in .log .aux .toc .lot .lof do R=`echo $T | sed s/\.tex$/$E/` echo rm $R done done ---end--- Copy all the lines between begin and end into a file called whatever you want (let's assume it's "TeXtidy.sh"). You invoke it from Terminal as $ . ./TeXtidy.sh start_dir_name where start_dir_name is the directory you want to start the recursion from. (Note that is "dot space dot slash" at the beginning.) I haven't commented it at all but the way it works is to find the full pathname of all files in dirs below the start dir that end with the extension .tex. E.g. T = ~/start_dir/dir1/dir2/my_tex_file.tex The inner loop replaces the ".tex" at the end with ".log", ".aux" etc in turn and tries to remove the file. If it succeeds then great; if not then it doesn't matter - ignore any error message and just move onto the next. As it stands above, it only lists out the files that it will try to delete. Just remove the echo before the rm to actually delete when you are happy that it does actually do what you want. To add more file extension types to match the "etc" in your post, just extend the list in the line starting "for E". Note that it doesn't do anything smart about files with extensions that don't exist so rm might give lots of 'not found' type errors. You can always re-direct errors to /dev/null. If you want to see an AppleScript version as well then I could knock one up in the next day or so when I have a bit of spare time. > > And one to open a pdf file in Preview, change page size/orientation to > DL envelope/landscape, identify which pages in the pdf file have a paper > size matching DL envelope (job made easier by the fact that they're all > at the end - and I'd not mind typing in a single number if the machine > couldn't work that bit out), print 'em out using single sided best > quality printing (defined by a preset), and then put page > size/orientation back to A4 portrait. This is harder because it depends on what scripting support is built-into Preview and/or the print dialogue handler. I'll have a go but it might end up being specific to my printer rather than yours. Haven't got time now but will have a look. >> (And feel free to contact me off line if you'd >> prefer) I quite like AppleScript (having scripted in virtually every OS >> and language over the years). The biggest problem I find is where the >> app doesn't support AppleScript fully so the promise is tantalising but >> the reality less so. > > The biggest problem is simply persuading AppleScript to perform *ANY* > tasks, I find. I've found it nearly impossible to figure out what > scripting dictionary entries do or how to use them. One other problem > is the lack of ability to control data types, and AppleScript's tendency > to pick the wrong data type for the job in hand. Not to mention the > fact that I found out the hard way Apple's totally uninterested in > keeping AppleScript stable, or so it seems. Agreed that finding the dictionaries for applications can be a right royal pain. As for data types - I just develop patiently one small bit at a time and looking carefully at the results. > I did once manage to cobble together some AppleScripts I found useful to > use with LaTeX. > > I downloaded, printed out, and read a lot in the AppleScript reference > manual from Apple, I bought AppleScript for Dummies which I read all of > (it's very bad), I read many on-line guides. It is very much a case of: you are expected to know which command to use, and only need the manual to remind yourself how to use it. I just delved through all the examples to get me started and experimented from there. > It took several weeks to figure out how to write scripts to delete - > look, you run TeX on a *.tex file, you get a *.pdf output (shutup), and > also a *.log file, usually a *.aux file, and often other debris too. I > found out how to write a script that'd delete such files, but never > could work out how to get it to work recursively. > > Anyway, like I say, after several weeks hard slog, I got the above > script working, and a few others. Never could get it working > recursively - but I could have written a Basic program to do the job in > minutes. Recursively, too - dead easy. Impossible with AppleScript, so > it seemed. Standard way to do recursion in AppleScript is to define a function that calls itself. I do remember (back in MacOS 7 days) taking ages and ages to find an example of how to create a funtion though. :-) > Anyway, then I went from MacOS 7.6.1 to 9.0.4 and all my scripts broke. > Since I had no idea why they worked in the first place, I couldn't fix > 'em. > >> That said, if something can't be scripted in >> AppleScript then it is unlikely to be scriptable in Bash or Perl on the >> Mac either. > > For me, the problem is that there seem to be no good learning resources > for *ANY* scripting language or indeed any programming language I can > find out about on Macs. Haven't looked for one so can't really help here. Maybe someone else has some suggestions? Regards -- Bruce Horrocks Surrey England (bruce at scorecrow dot com)
From: Ben Shimmin on 22 Nov 2009 20:07 Tim Streater <timstreater(a)waitrose.com>: > On 22/11/2009 22:09, Rowland McDonnell wrote: >> For me, the problem is that there seem to be no good learning resources >> for *ANY* scripting language or indeed any programming language I can >> find out about on Macs. > > Have you tried PHP? That has a large set of APIs to all sorts of things, > a reasonable C-like syntax, easy string handling, and a very good > website where the docs appear to be written in an adult fashion (unlike > perl). I use no other. PHP has 53 built-in functions which start with `array'. I think that's quite a good indication of the sort of language it is. b. -- <bas(a)bas.me.uk> <URL:http://bas.me.uk/> `Property, marriage, the law; as the bed to the river, so rule and convention to the instinct; and woe to him who tampers with the banks while the flood is flowing.' -- Samuel Butler, _Erewhon_
From: zoara on 22 Nov 2009 20:46
T i m <news(a)spaced.me.uk> wrote: > On Fri, 20 Nov 2009 12:48:32 +0000, thewildrover(a)me.com (Andy Hewitt) > wrote: > > >> It does and that's *the point* of this dongle. It has a virtual CD > >> thing like these USB BB dongles that autorun on insertion. > > > >OK, fair enough. The Maplin page doesn't make that clear. > > I thought I had though. 'You plug it in and it backs up all your data' > . ;-) Probably most of us were confused, because who in their right mind leaves those autorun seetings turned on? -z- -- "And the tiny universe compiles." http://powazek.com/posts/1655 |