Watch folder for new file when file appears run script then delete fil

Hello,

I have been trying all sorts of workarounds for this problem at hand which is

I have a macmini used as an installation piece in a gallery.
this macmini is running a php webscript when the php script comes to an end the user has a printout from an attached printer
The problem is that I do not want the user to be able to edit the settings in the print confirmation window
I have been trying many different way to resolve this which include disabling the rights to edit print setting etc

Now I have it so when the final page loads of the php script webpage a javascript window calls the print function before this javascript is called I have
php create a txt file in a folder, what I would like to do is

Either have an applescript watch the system processes for when the print window opens (is called from safari) and then run the appelscript below

press print button


tell application "System Events"
	tell process "Safari"
		activate
		set frontmost to true
		delay 3
		key code 36
end tell
end tell

Or call this applescript via osascript such as

<?php shell_exec("osascript -l open /Library/Webserver/Documents/pressprint.app'"); ?>

or

<?php shell_exec("osascript -l open /Library/Webserver/Documents/pressprint.scpt'"); ?>

The only problems is I cannot get osascript to work with this shell_exec I can get it t work from terminal but not from www user, I could run the www as root as this machine will never be n the net and also be in a small room, but then I reall do not know how to call osascript via php by root or do I just run webserver completely a root

Or final last hope to get this to work

would be have an open applescript running 24/7 checking for this txt file that php creates on page load, when it finds the file run pressprint.app and then delete file after running
but my applescripting is really no good just a noob


on idle
tell application "Finder"
if the (count of files) in folder watchFolder > 0 then
wait 1 sec
if the (count of files) in folder watchFolder > 1 then

tell application "System Events"
	tell process "Safari"
		activate
		set frontmost to true
		delay 3
		key code 36
then delete file

end idle

But as you can see I could really need some help, thank you for taking the time to read my long winded problem
Sincerely
David

Model: Maacmin 1.44 PPC
AppleScript: 1.0
Browser: Safari 2.04
Operating System: Mac OS X (10.4)

Hi David,

I have no idea about php, but maybe you can call this script from somewhere,
which prints the frontmost document without the print dialog

tell application "Safari" to print document 1 without print dialog

That would work, but I am then still left with how to call it when the correct page is loaded…

Thank you for your advice I did not know that I could actually tell safari to print without confirmation in such a manner…

Ok I have managed to get the osascript to work by changing the webserver to run as the user that is logged in…

This make me very happy

but also short lived, as I am using the kind StefanK s script

tell application "Safari" to print document 1 without print dialog

now I need to be able to print the contents of an iframe in the page 1

I was using previously javascript to focus on the iframe and then print it which is the reason why I was trying to get applescript to press the print button to confim printing

Javascript
function printPage(ifr) {
if (ifr.location.href != “about:blank”){
ifr.focus(); //need to focus to print iframe’s contents not the main window’s
ifr.print();
}
}

function loadPage(url){
var win = window.open(url, ‘printFrame’);
return false;
}

and then this for the iframe

Ok I am trying to get this to work


tell application "Safari" to {print document frameElement, hhh without Dialog}


does anybody know anything about getting the iframe with the dom element from safari??

ANy help would be great fullly received

Hi,

you cannot print single frames of a document with AppleScript,
but Safari can understand javascript via the do javascript command

do JavaScript (verb) Applies a string of JavaScript code to a document. (from Safari suite)

Command Syntax
do JavaScript reference in document

Parameters
Parameter Required Type Description
direct parameter required reference the object for the command
in required document The document that the JavaScript should be applied in.

Ok thank you,

I am afraid I chickened out of this.

I just rewrote the pages so that the iframe that I wanted to print loaded before the final page for 1 second and then printed using the apple script above and then refreshes to final page

Thank you for your input and inspiration
Have a nice weekend

David