Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Script corrupt? Please help

Hi all,


today i just got this message from my script "Could not run this script because of a program error" it says error "-1752".

The point is this script was running fine for hourse, I think I tried it something like 50 times...


A possible scenario to me is it that while running the computer was switched off (by cable) and it became corrupted.

Do you think it's possible?

Do you have any advice on how to manage this possible problem in the future? (something like "on error ..." launch a backup copy)


Thanks a lot!

Posted on Nov 6, 2012 11:34 AM

Reply
11 replies
Sort By: 

Nov 6, 2012 12:17 PM in response to twtwtw

thanks twtwtw,


do you think it's possible to prevent this from happening again?

This script (as said, it is actualy an app) it is a very important one, launched as the system starts.

So it would be really helpful to know if in the future, if this happens, there is some automated trick.


I was thinking two things:

1) setting some handler, like "on errore -1752 tell application app_backup to run"

this would imply having a second application there, just in case the first one gets corrupted.


2) launching a second application together with the first one, and if this second one sees that after let's say 60 seconds, the first application has not run (i could use the creation of a folder as a flag) it will launch the app_backup (again, it will be a copy of the first one)


Looks a little complex, but in my situation i really cannot afford this script not to run. SO i have to invent some reliable exit strategy...! ;-)


What do you think would be a better solution...?

Reply

Nov 6, 2012 12:21 PM in response to personal_username

Nothing is going to help if the computer is switched off; keep a backup copy.


More generally, I've never seen this happen, and I use scripts a lot. That leads me to think there's something in your script design that makes it vulnerable to this kind of thing. without seeing your script, though...

Reply

Nov 6, 2012 12:29 PM in response to twtwtw

It is the first time it happens to me, as well...!

That's probably because I force quit my system severl times (to make sure it was 1000% stable) and doing so i think the script got corrupted (possibly the computer force quit when that app was running...)

btw, here's the script.

It soes several things on system startup..


---------------------------------- START SCREENSAVER ----------------------------------


try

tell application id "com.apple.ScreenSaver.Engine" to launch

end try



---------------------------------- SET VARI ----------------------------------



set giorno to date string of (current date)

set ora to time string of (current date)

set ComputerName to do shell script "networksetup -getcomputername"



---------------------------------- FORCE WIFI CHECK ----------------------------------


--(*

try

do shell script "Sudo /path/wifiboot start > /dev/null 2>&1 &" password "pwd" with administrator privileges

end try

--*



---------------------------------- AUDIO MAX ----------------------------------



set volumeoutput volume 100



delay 2



---------------------------------- DONGLE 1




--REALTEK--


try

do shell script "open /Applications/Wireless\\ Network\\ Utility.app > /dev/null 2>&1 &"

end try


delay 5



---------------------------------- DISABLE OTHER AUDIO DRIVER ----------------------------------



try

do shell script "Sudo kextunload /system/library/extensions/logmeinsounddriver64.kext" password "pwd" with administrator privileges

end try


delay 1


---------------------------------- CREA CARTELLA "cloud" se non c'è ----------------------------------


try

do shell script "mkdir /path/.cloud/ > /dev/null 2>&1 &"

end try


---------------------------------- CREA CARTELLA "o" ----------------------------------


try

do shell script "mkdir /path/.Reports/o/ > /dev/null 2>&1 &"

end try


---------------------------------- RIMUOVE CARTELLA "v" ----------------------------------


try

do shell script "rm -r /path/.Reports/v/ > /dev/null 2>&1 &"

end try


---------------------------------- RIMUOVE CARTELLA "s" ----------------------------------


try

do shell script "rm -r /path/.Reports/s/ > /dev/null 2>&1 &"

end try


---------------------------------- RIMUOVE CARTELLA "r" ----------------------------------


try

do shell script "rm -r /path/.Reports/r/ > /dev/null 2>&1 &"

end try


---------------------------------- RIMUOVE CARTELLA "h" ----------------------------------


try

do shell script "rm -r /path/.Reports/h/ > /dev/null 2>&1 &"

end try


---------------------------------- RIMUOVE CARTELLA "m" ----------------------------------




try

do shell script "rm -r /path/.Reports/m/ > /dev/null 2>&1 &"

end try


---------------------------------- PULIZIE 1 ----------------------------------




try

close access "/path/.Reports/report.txt"

end try


set Report to "/path/.Reports/report.txt"

try


close accessReport

end try





---------------------------------- PULIZIE 2 ----------------------------------




try

do shell script "killall nino > /dev/null 2>&1 &"

end try



---------------------------------- DONGLE 2 ----------------------------------



--RALINK--


try

do shell script "open /Applications/Ralink\\ Wireless\\ Utility//WirelessUtility.app > /dev/null 2>&1 &"

end try





---------------------------------- SCRITTURA FILE ----------------------------------



try

set the_file to (open for accessReport with write permission)


writereturntothe_filestarting ateof


write "| | | " & ComputerNametothe_file


writereturntothe_filestarting ateof

write "| | | NINO - O N | | | " & giorno & " " & ora to the_file


writereturntothe_file


close accessthe_file

end try



---------------------------------- MEDIA ----------------------------------



try

do shell script "open /path/.media.app > /dev/null 2>&1 &"

end try


delay 5



---------------------------------- CHECK > 20 GB! ----------------------------------



tell application "System Events"

set myFolder to "/path/.cloud"

set myFolderSize to physical size of foldermyFolder

if myFolderSize > 20 * (2 ^ 30) then


try

do shell script "rm -r /path/.cloud/ > /dev/null 2>&1 &"

end try


end if

end tell



---------------------------------- FTP ----------------------------------


try

do shell script "curl --ftp-create-dirs -T " & Report & " ftp://nino/reports/" & ComputerName & "/ --user nino:dsa > /dev/null 2>&1 &"

end try

do shell script "sudo nvram SystemAudioVolume='%80'" password "pwd" with administrator privileges




---------------------------------- DROPBOX ----------------------------------


tell application "Dropbox" to activate





--(*

---------------------------------- CHECK CONNECTION ----------------------------------




delay 20


try

set pong to do shell script "ping -c 10 www.google.com"



---------------------------------- OK! NINO ACTIVE!----------------------------------


if pong does not contain " 0 packets received" then do shell script "afplay /path/OnAir.wav > /dev/null 2>&1 &"



---------------------------------- NO! PRIVATE NEWORK THEN----------------------------------


on error


try

do shell script "open /path/adhoc.app > /dev/null 2>&1 &"

end try


end try

--*)


--REALTEK--


try

do shell script "open /Applications/Wireless\\ Network\\ Utility.app > /dev/null 2>&1 &"

end try


delay 5



---------------------------------- VUOTA CARTELLE VUOTE .CLOUD IF ----------------------------------



set folderToClean to "/path/.cloud"

tell application "System Events"

set emptyFolders to path of folders of folder folderToClean whose (disk items whose visible is true) = {}

end tell

tell application "Finder"


deleteemptyFolders


emptytrash

end tell

Reply

Nov 6, 2012 1:42 PM in response to personal_username

well, it might be corruption, but it also might be that one of the file handlers was left open; possible if the computer went down during one of the write-to-file moments. That would throw a fatal error, but I don't know if it would be reported from within an application package. I doubtl it will happen again, but if you want to be sure about the file handler thing, rewrite all your open for access lines on the following pattern:


try


open for accessfilepath

on error


close accessfilepath


open for accessfilepath

end try


if the file is open the script will catch the error then close the file and reopen it.

Reply

Nov 7, 2012 2:12 AM in response to Jacques Rioux

thanks you both for your help, two things:


@twtwtw: since it happens on startup I doubt it depends on problems accessing a file (which may be already opened). Am I wrong?


@Jacques: I removed it. Was it a optimization suggestion or do you think this could be responsible for my problem?


Thanks both, again!

Reply

Nov 7, 2012 5:48 AM in response to personal_username

yes, you're right. a restart would close any open file pointers.


never use sudo in do shell script; it's a security risk apparently. read this tech note.


The only other thing I can think of is that you leave the script hanging in delay a lot. delay isn't like unix sleep; delay stops script execution but leaves the script active. but that's just a guess. If it were me, I'd get rid of all the delays entirely. your do shell scripts all spawn separate processes and there's no obvious dependencies - just fire them all off, let them do their stuff concurrently, and let the script app exit. or if you really need delays, rebuild the script app using an idle handler, which is more system-friendy.

Reply

Nov 8, 2012 9:23 AM in response to twtwtw

Thanks twtwtw!


btw, I'm not sure what would be the idle handler...

For instance, in this case I need to wait a little bit (for instanceI have the script to return me some information about the CD inside...) so how could i implement what you say in this?

And, most importantly, is this connected to the fact that i cannot quit this script? I can only force quit...




if application "iTunes" is running then

tell me to quit


else


repeat while application "iTunes" is not running



set r to do shell script "/usr/bin/drutil status"



delay 10



-- RESTART



if r contains "CD+R" then


try

do shell script "afplay /Users/DEMO/Desktop/cd-wrong.wav > /dev/null 2>&1 &"

end try

try

do shell script "drutil eject"

end try



else if r contains "DVD-ROM" or r contains "DVD+R" or r contains "DVD-R" then

try

do shell script "afplay /Users/DEMO/Desktop/OFF.wav > /dev/null 2>&1 &"

end try

try

do shell script "open /Users/DEMO/Desktop/prog-OFF.app > /dev/null 2>&1 &"

end try

try

do shell script "drutil eject"

end try








-- CD-R OK


else if r contains "CD-R" then


try

do shell script "afplay /Users/DEMO/Desktop/OFF.wav > /dev/null 2>&1 &"

end try



-- CD VOID



if r contains "blank" then

tell application "iTunes" to activate




-- NOT VOID


else if r does not contain "blank" then



try

do shell script "killall 'iTunes' > /dev/null 2>&1 &"

end try


try

do shell script "afplay /Users/DEMO/Desktop/cd-wrong.wav > /dev/null 2>&1 &"

end try

try

do shell script "drutil eject"

end try


end if



end if


end repeat

end if

Reply

Nov 8, 2012 10:30 AM in response to personal_username

lol - if you'd have mentioned earlier that you always have to force-quit the script app, I would have suggested that as a likely vector of corruption. 😁


I really don't know why your script won't quit. All I can do is point out a few misconceptions you seem to have and suggest some avenues for debugging.


first, There are two breeds of script app - normal and stay-open apps. Normal script apps do what they are supposed to do then quit the same way a script does. Stay-open apps stay open until they are told to quit. If it's the former case, then one of your do shell scripts is hanging (not one of the ones you release as a separate process) and that's hanging the entire script app. you need to examine the run log and/or put in log statements to narrow down where the hang is. If it's a stay-open script, your logic might not be asking it to quit. You have a quit statement on the second line, but nothing at the end - unless there's more code that I don't see the script execution will stop at the end, but the script app itself will remain open. you might be able to close it by running another sript that says tell application "/app/path" to quit.


idle handlers are exactly what they sound like. if ou have a stay-open script (they do nothing in normal script apps), the system will periodically poll the app to see if it wants to do anything. you can catch that idling poll with the following handler:


on idle


--do some stuff

return secondsToNextIdlePoll

end idle


The way you'd use it in a script like this would be to put your various do shell scripts into separate handlers, and then use IF statements to call each one from the idle handler on sequential idling polls. You can set the poll time to whatever value works in each case.


just a note on do shell script. if you write it like so:


set x to do shell script "some_unix_call"


applescript will wait until it completes and returns before moving on, so you don't really need to put any time spacers afterward. If you write it like so:


set x to do shell script "some_unix_call &> /dev/null &"


Applescript will detach the script and move on immediately. '&> /dev/null' is shorthand for '> /dev/null/ 2>&1'.


also, I always recommend that people give preference to applescript commands over do shell scripts - e.g. instead of do shell script "killall 'iTunes' > /dev/null 2>&1 &" use tell application "iTunes" to quit, or instead of do shell script "drutil eject" use tell application "System Events" to eject disc discName. It's sometimes more stable to do so, and certainly easier to read and debug

Reply

Script corrupt? Please help

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.