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

Error 10810 when running applescript remotely

So "final" product here. I'm no applescripter so my code is probably inefficient. As such I keep running into a -10810 error and from my googling and research I think it's a runaway process (or a few of them) created by this script. I run it through Casper remote. It's a compiled script for compatibility with Casper Remote. Running as a standalone app (or as a compiled script on the local desktop) it works just fine. It's only through Casper Remote that I get this error and only sometimes. The script works even when no one is logged in. Casper Remote runs as an admin and forces sudo when it needs to.


Any ideas as to what might be causing the failure? The script fails very quickly when it does. It certainly does not get to the point where it gathers all apps on the computer.


TIA!

Andrew





(*This script should be run first on a computer to be upgraded.

It collects the size of the users's homefolder and any folders

common to all users (Workfolder, PAGEFOLDER, etc). Common units get

all users transfered. It also collects apps installed in /Applications. It is to

be run again on the new computer to verify that all data and apps were

copied over correctly. It outputs the data to a log at

/netappv2/MacPackaging/FY12MacDAC-UserMigration titled with the

User's username, old mac name *)


on run argv


------------------------------


-- Define static variables --


------------------------------



---- "\n"


-- Capture the user's name (passed from Casper Remote)

set userName to item 4 of argv


-- if a username was not passed to the script, quit immediately

if userName = "" then

do shell script "echo No username specified! Try again with a valid username"

error number -128

else if userName is in {"Common", "common", "COMMON"} then

do shell script "echo **********THIS IS A COMMON UNIT. ALL USERS WILL BE TRANSFERED! **********"

end if



-- Capture computer name and current date

set computerName to computer name of (system info)

set currentDate to current date



-------------------------


-- Define file access --


-------------------------



-- We first have to create a file so we can reference it via Applescript for writing. We do this via the shell

set shellLogFile to computerName & "-" & userName & ".txt"

do shell script ("mkfile 10k /private/var/root/Desktop/" & shellLogFile)



-- Make a directory on the server particular to this user and computer since two reports will be made: one for the old computer and one for the new

set logFolder to computerName & "-" & userName

do shell script "mkdir -p -m 777 /Volumes/MacPackaging/FY12MacDAC-UserMigration/" & logFolder



-- Open a text file for writing the DAC data collection information. Alias it to the file we just created


-- the file is located on roots desktop, but it is aliased to the current user's desktop (if one is logged in)

set logFile to (((path to desktop) as string) & computerName & "-" & userName & ".txt") as alias


open for accesslogFile with write permission


set eof of logFileto 0



---------------------------


-- Write log headers --


---------------------------



-- Write relevant user and computer information to the log file

if userName is equal to "common" then

write "**********THIS IS A COMMON UNIT. ALL USERS WILL BE TRANSFERED! **********

" tologFile

write "

" tologFile

end if


write "Report run date: " & currentDate & "

" tologFile

write "User to be migrated: " & userName & "

" tologFile

write "Computer to be migrated: " & computerName & "

" tologFile

write "=========================" & "

" tologFile


write "

" tologFile



----------------------------------------


-- Begin data collection output --


----------------------------------------



-- First check for the existence of partition "work"

write "Folders on Work partition to be transfered" & "

" tologFile

write "========================================" & "

" tologFile

set workPath to "Work" --we are only looking for partition "Work"

tell application "System Events"

if workPath is in (get the name of every disk) then -- list all partitions and check for "Work." If found, set folderList to the contents of Work

set folderList to list folder workPath without invisibles

else

set workPath to (get the name of every disk) -- if "Work" is not found, list the mounted partitions and exit

write "No Work partition! Available partitions are: " & workPath & ". Exiting." & "

" tologFile

do shell script "echo No Work partition!"

do shell script "echo Available partitions are: " & workPath

close accesslogFile

error -128

end if

end tell



-- Next write the root level contents of the Work partition and their sizes. These main folders and their entire contents (except Users) will be transferred. For user folders, only the /Users/username and Users/Shared folder will be transferred

set totalSize to 0 --set a count for the size of each folder found. This will be the total size of all data to be migrated

repeat with aFolder in folderList

if aFolder contains "Users" then

set userFolder to "/" & aFolder & "/" & userName-- rename the folder to the explicit path to the users home folder (name provided when the script was run), since we aren't interested in any other user folder

set sharedFolder to "/" & aFolder & "/Shared" -- create another variable to hold the Shared folder since we need to copy this as well


---------------------------------------------

set UNIXFolder to quoted form of POSIX path of userFolder

set folderSize to (do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of the users home folder

set totalSize to totalSize + folderSize

writeuserName & " home folder - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "

" tologFile

set UNIXFolder to quoted form of POSIX path of sharedFolder

set folderSize to (do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of the Users/Shared folder using the same method as above

set totalSize to totalSize + folderSize

write "Users/Shared - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "

" tologFile

else if aFolder does not contain "Users" then

set UNIXFolder to quoted form of POSIX path of aFolder

set folderSize to (do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of aFolder if other than "Users"

set totalSize to totalSize + folderSize

writeaFolder & " - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "

" tologFile

end if

end repeat

write "____________________" & "

" tologFile

write "Total copy size: " & CalcFolderSize(totalSize) & " " & KBMBGB(totalSize) & "

" tologFile


write "

" tologFile



-- Record all departmental apps that need to be installed on the new mac

write "Departmental apps to install on the new mac" & "

" tologFile

write "===========================================" & "

" tologFile


-- A pre-defined list of departmental apps. These apps are not included in the AG Core image and need to be installed on the new mac. All relevant transferrable apps are in the Applications and Utilities folders. Apps installed elsewhere are not AG standard and do not get transferred

set theApps to {"Adobe Acrobat 7.0 Professional.app", "Adobe After Effects CS4.app", "Adobe After Effects CS3.app", "Adobe Fireworks CS3.app", "Adobe Flash CS4.app", "Adobe Flash CS3.app", "ColorEyes Display Pro.app", "ColorThink 2.2.1b2", "Corel Painter X.app", "DiskTracker 2.3.2", "DiskTracker.app", "Dreamweaver.app", "EPSON Scan.app", "Fetch.app", "formZ RenderZone Plus.app", "Google Earth Pro.app", "Google Earth.app", "iMovie.app", "Keyspan Serial Assistant.app", "Flash 8.app", "Microsoft Excel.app", "Microsoft Excel", "Microsoft Word.app", "Microsoft Word", "Microsoft PowerPoint.app", "Microsoft PowerPoint", "PhotoZoom Pro 2.app", "Product Ingest.app", "Product Tag.app", "Art Ingest.app", "ProfileMaker", "TextWrangler.app", "Toast Titanium.app", "ToolCrib.app", "Winclone.app", "Suitcase Fusion 2.app", "Suitcase Fusion 3.app", "BRASS.app", "Final Cut Pro.app", "Pro Tools LE.app", "LightWave", "VMware Fusion.app"}


set appsPath to (path toapplications folder)

tell application "Finder"

set appList to name of every application file of entire contents of folder appsPath

end tell

repeat with anApp in theApps

if appList contains anApp then

set anAppID to id of (application anApp)

if anAppID is not equal to "????" then

tell application "Finder" to tell (application file id anAppID)

set vers to version of application fileidanAppID

set parentFolder to name of its container

end tell

if parentFolder is in {"Applications", "Utilities"} then

set parentFolder to ""

end if


write anApp & "

" & "Version: " & vers & "

" & parentFolder & "

" tologFile

write "--------------------------------------" & "

" tologFile

write "

" tologFile

else if anAppID is equal to "????" then

write anApp & "

" tologFile

write "--------------------------------------" & "

" tologFile

write "

" tologFile

end if

end if

end repeat


write "

" tologFile



-- Collect all the printers that need to be installed on the new Mac

write "Printers to install on the new mac" & "

" tologFile

write "===================================" & "

" tologFile


(*tell application "Printer Setup Utility"

set printerList to the name of every printer as list

end tell

repeat with aPrinter in printerList

write aPrinter & "

" to logFile

end repeat*)

set printerList to do shell script "lpstat -a | awk '{print $1}'" as text


writeprinterList & "

" tologFile


close accesslogFile


-- edit file permissions so everyone can read it

do shell script "chmod 755 /private/var/root/Desktop/" & shellLogFile


-- copy the file to macpackaging for later use

do shell script "ditto /private/var/root/Desktop/" & shellLogFile & " /Volumes/Macpackaging/FY12MacDAC-UserMigration/" & logFolder

end run


-- subroutine for converting folderSize

on CalcFolderSize(KBParam)

if KBParam ≥ 1048576 then -- convert to GB

return (KBParam / 1024 / 1024)

else if KBParam ≥ 1024 then -- convert to MB

return (KBParam / 1024)

else

return (KBParam)

end if

end CalcFolderSize


-- subroutine for determing KB, MB, or GB

on KBMBGB(paramSize)

if paramSize ≥ 1048576 then -- 1GB

return ("GB")

else if paramSize ≥ 1024 then -- 1MB

return ("MB")

else

return ("KB")

end if

end KBMBGB

MacPro 2x2.66GHz Dual Core Xeon, 4GB RAM,, Mac OS X (10.6.4)

Posted on Jun 6, 2011 11:28 AM

Reply
8 replies

Jun 6, 2011 12:31 PM in response to Andrew Caldwell

You've given a long script and not a lot of info to work with:

  • at what point in the script execution does the error occur?
  • what is different about the cases where it happens from cases where it doesn't happen?

It's not like we can test this easily without access to your setup. At a guess, though, I'd say your problem is one of two things:

  • at lines 112-20 or so - where it says repeat with anApp in theApps - the script may be trying to open all of those apps, which might choke the system and throw that particular error
  • in general, you have a senseless amount of write and do shell script commands - that might choke things as well (each DSS opens a separate shell and each write probably makes a new file pointer)

As a rule, don't use do shell script excessively: use it where you get an advantage in speed, flexibility, or capability, but don't use it to make folders, get disk or file sizes, or other things that are more effectively done through the Finder, System Events, or AppleScript itself, and don't ever use DSS to run an echo command - there's never a reason to do that. Also, if you need to do multiple writes to a file, use the open for access command, assign it a file pointer, the do all your writes to that file pointer and close it with the close access command.


If the script actually is trying to open all of those applications, there are ways to get the version and parent folder info without that happening. let us know if that's the case.

Jun 6, 2011 4:07 PM in response to twtwtw

It must be the fact that I keep invoking the shell and/or writing out to the text file then since it's pretty random as to when I get the error message. It tends to happen on machines with more apps and/or more running processes than ones without. It fails on my own computer - I have a few dozen processes running before the script starts anyway, and it fails shortly thereafter - but only when run through Casper Remote. If I run it from within AS Editor it works fine.


I did not think I was invoking the app by getting the app id from the name; at least, it does not look like it's trying to open each one.


If I use an open for access command for each block of writes then close the pointer, rather than a single open for access like I have now, do I just assign the pointer to eof?


I probably should just learn to use AS for most of the other operations I have DSS's for. I'm a shell-scripter so I tend to use DSS more than I should. I thought AS was closing the sh processes faster than it is.


Is there a way to make Applescript write to stdout? Casper Remote does not understand display alerts or anything like that, hence the DSS echo - I need the tech running the script to see if they forgot to give it a username if they see a failure - and that would only show up in the Casper Remote log where it only understands writes to stdout.

Jun 6, 2011 4:47 PM in response to Andrew Caldwell

to use a consistent file pointer, do it like so:


-- open the file

set pointer to open for access "/path/to/file" with write permission

-- delete the file contents, if the file already exists (otherwise it will append at the end)

set eof of pointerto 0

-- do a couple of writes

write "dah dum dah dum" to pointer

write return & return & "yadda yadda" to pointer

-- close the file

close accesspointer


if you want something from applescript to appear in the terminal when running from the command line (via osascript), just use the log command


log "This text will appear in the terminal"


Finally, there's nothing wrong with writing a shell script and running that via Casper (I assume Casper can run shell scripts as well as applescripts), but yeah, if you want to use applescript you should get used to using applescript. The more your code gets spread across different languages, the more you open the door to silly errors, quoting problems, and unexpected difficulties.

Jun 8, 2011 9:20 AM in response to twtwtw

Ok I give up. I can't seem to find anywhere on how to get Applescript to get the size of the value (either a file or folder) contained in a variable, heck I don't even know how to verify if a variable contains a file or folder. I know the absolute path will always be /Volumes/Work/<file-or-folder>. anything else should be ignored. I want to output the name and size of each individual item the script finds on the root of the Work volume. The name is easy, I just write the name of the variable. Here's the code I am working on:


...

else if aFolder does not contain "Users" then

--set UNIXFolder to quoted form of POSIX path of aFolder

set folderSize to (size of (aFolder)) --(do shell script "du -k /Volumes/Work" & UNIXFolder & " | tail -rn1 | awk '{print \"\" $1}'") as integer -- extract the size of aFolder if other than "Users"

set totalSize to totalSize + folderSize

writeaFolder & " - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "

" tologFile

end if


Originally had the script issuing a DSS to process the size, but each folder would open 3 processes (one for the DSS, one for tail, and 1 for awk). This wasn't so bad on my machine with only 4 items on the work volume, but some of these computers have 10 or more items -- I think this is where that 10810 error was coming in.


Message was edited by: Andrew Caldwell

Jun 8, 2011 10:47 AM in response to Andrew Caldwell

to get the size of a file or folder, call System Events.app:

tell application "System Events"

set folderSize to (physical size of aFolder) div 1024

end tell

set totalSize to totalSize + folderSize


writeaFolder & " - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "\n" tologFile


the div 1024 bit mimics the -k option in du. If you want to determine whether the path is a file or folder, you can do that through System Events as well, for instance:


tell application "System Events"

if class of disk itemaFolder is folder then


--process folder

else


--process file

end if

end tell

Jun 8, 2011 1:34 PM in response to twtwtw

So AS can't get the physical size of the folder it finds. I think I know the reason though. The script lists the contents of the Work volume in this snippet:


set workPath to "Work" --we are only looking for partition "Work"

tell application "System Events"

if workPath is in (get the name of every disk) then -- list all partitions and check for "Work." If found, set folderList to the contents of Work

set folderList to list folder workPath without invisibles

else if

... stuff ...

end if

end tell



Then later I have it doing this:


else if aFolder does not contain "Users" then

tell application "System Events"

set folderSize to (physical size of aFolder) div 1024

end tell

set totalSize to totalSize + folderSize


writeaFolder & " - " & CalcFolderSize(folderSize) & " " & KBMBGB(folderSize) & "


and I get the following from the AS editor events pane:



tell current application


system info


--> {AppleScript version:"2.1.2", AppleScript Studio version:"1.5.1", system version:"10.6.7", short user name:"acaldwell", long user name:"AC Andrew Caldwell (8318)", user ID:1.092545022E+9, user locale:"en_US", home directory:alias "Work:Users:acaldwell:", boot volume:"AG2025", computer name:"AG2025", host name:"ag2025.amgreetings.com", IPv4 address:"10.104.20.113", primary Ethernet address:"00:17:f2:07:ec:dc", CPU type:"Intel 80486", CPU speed:2660, physical memory:4096}


current date


--> date "Wednesday, June 8, 2011 4:24:49 PM"


path todesktopasstring


--> "Work:Users:acaldwell:Desktop:"


open for access "Work:Users:acaldwell:Desktop:AG2025-acaldwell.txt" with write permission


--> 47


set eof 47 to 0


write "Report run date: Wednesday, June 8, 2011 4:24:49 PM

User to be migrated: acaldwell

Computer to be migrated: AG2025

=========================


" to 47


write "Folders on Work partition to be transfered

========================================

" to 47

end tell

tell application "System Events"


get name of every disk


--> {"AG2025", "Work", "home", "net", "Public", "MacPackaging"}


list folder "Work" without invisibles


--> error number -10004

end tell

tell current application


list folder "Work" without invisibles


--> {"Page4 Folder", "PAGE4BUILDER", "Users", "zz_LastFolder"}

Result:

error "Can’t get physical size of \"Page4 Folder\"." number -1728 from «class phys» of "Page4 Folder"



Now I tested the tell system event portion in another editor with this code

set aFolder to path tohome folder

tell application "System Events"

set folderSize to (physical size of aFolder) div 1024

end tell


and got the right result. So I think that I can't get the size because it is not showing the path to each of these items, just the name of them. Is there a way to set a variable to the path to each of the items it finds? I think then it'll get the sizes right....


Thanks!

Andrew

Jun 8, 2011 2:06 PM in response to Andrew Caldwell

If I understand what you're trying to do, then you need to do it something like what follows:


tell application "System Events"

if exists disk "Work" then

set workDiskItems to disk items of disk "Work" whose visible is true

set totalSize to 0

repeat with thisDiskItem in workDiskItems

if name of thisDiskItem is "Users" then

set userSize to (physical size of disk item "<username>" of thisDiskItem) div 1024

write "Users - " & CalcFolderSize(userSize) & " " & KBMBGB(userSize) & returntologFile

set sharedSize to ((physical size of disk item "Shared" of thisDiskItem) div 1024)

write "Shared - " & CalcFolderSize(sharedSize) & " " & KBMBGB(sharedSize) & returntologFile

set addedSize to userSize + sharedSize

else

set addedSize to (physical size of thisDiskItem) div 1024

write (name of thisDiskItem) & " - " & CalcFolderSize(addedSize) & " " & KBMBGB(addedSize) & returntologFile

end if

set totalSize to totalSize + addedSize

end repeat

end if

end tell


notice in line 3 that I get reference objects to the contained disk items, rather than just the names, because I can extract the name from the object when I need to.

Error 10810 when running applescript remotely

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