Export hard drive dir as XML via AppleScript?

Does anyone know of a utility (even an AppleScript) that can take my hard drive (or a specific folder therein) and write the whole directory out (including nested folder structures) as an XML document? Need it urgently!

global eof_character
global indent_string
set eof_character to the ASCII character of 0
set indent_string to " "
set thestartingpoint to choose folder with prompt "Pick a folder to list as (not-quite-)XML." with invisibles and showing package contents
set include_invisibles to (the button returned of (display dialog "Do you want to include invisible items in the listing?" buttons {"No", "Yes"} default button "Yes") is "Yes")
set show_permissions to (the button returned of (display dialog "Do you want to include permissions (file owner, read/write/execute, etc.) in the listing?" buttons {"No", "Yes"} default button "Yes") is "Yes")
set output_file to open for access (choose file name with prompt "Where should the pseudo-XML be written?" default name "Not Really XML.xml") with write permission
try
     set the_info to info for thestartingpoint
     set the_kind to "folder"
     if the kind of the_info is "Volume" then set the_kind to "volume"
     set permissions_info to getpermissions_info(the_startingpoint)
     set the_contents to ""
     set insufficientaccess_tolist to "true"
     if item 1 of permissions_info is "1" then
          set the_contents to xmlfolder(the_startingpoint, indent_string, include_invisibles, show_permissions)
          set insufficientaccess_tolist to missing value
     end if
     set permissions_pairs to {}
     if show_permissions then
          set permissions_pairs to {{"permissions", item 2 of permissions_info}, {"owner", item 3 of permissions_info}, {"owner_id", item 4 of permissions_info}, {"group", item 5 of permissions_info}, {"group_id", item 6 of permissions_info}}
     end if
     write xml_entity("", the_kind, {{"name", the name of the_info}, {"creation_date", the creation date of the_info}, {"modification_date", the modification date of the_info}, {"extension_hidden", the extension hidden of the_info}, {"visible", the visible of the_info}, {"insufficientaccess_tolist", insufficientaccess_tolist}} & permissions_pairs, the_contents) to output_file as string
     close access output_file
on error msg number num
     close access output_file
     error msg number num
end try
on xmlfolder(thefolder, the_indent, include_invisibles, show_permissions)
     set the_result to ""
     set the_path to (the_folder as alias) as string
     set the_list to list folder the_folder invisibles include_invisibles
     repeat with x in the_list
          set the_item to ((the_path & x) as alias)
          set the_info to info for the_item
          set permissions_info to getpermissions_info(theitem)
          set permissions_pairs to {}
          if show_permissions then
               set permissions_pairs to {{"permissions", item 2 of permissions_info}, {"owner", item 3 of permissions_info}, {"owner_id", item 4 of permissions_info}, {"group", item 5 of permissions_info}, {"group_id", item 6 of permissions_info}}
          end if
          set standard_pairs to {{"name", the name of the_info}, {"creation_date", the creation date of the_info}, {"modification_date", the modification date of the_info}, {"extension_hidden", the extension hidden of the_info}, {"visible", the visible of the_info}}
          if the alias of the_info then
               tell application "Finder" to set the_original to (the original item of alias file the_item) as alias
               set the_result to the_result & xmlentity(theindent, "alias", standard_pairs & {{"original", the_original}} & permissions_pairs, "")
          else
               if the folder of the_info then
                    set the_contents to ""
                    set insufficientaccess_tolist to "true"
                    if item 1 of permissions_info is "1" then
                         set the_contents to xmlfolder(theitem, the_indent & indent_string, include_invisibles, show_permissions)
                         set insufficientaccess_tolist to missing value
                    end if
                    set the_result to the_result & xmlentity(theindent, "folder", standard_pairs & {{"insufficientaccess_tolist", insufficientaccess_tolist}} & permissions_pairs, the_contents)
               else
                    set the_result to the_result & xmlentity(theindent, "file", standard_pairs & {{"locked", the locked of the_info}, {"size", the size of the_info}, {"type", the file type of the_info}, {"creator", the file creator of the_info}} & permissions_pairs, "")
               end if
          end if
     end repeat
     return the_result
end xml_folder
on xmlentity(theindent, the_name, the_attributes, the_contents)
     set the_result to ""
     repeat with x in the_attributes
          set the_result to the_result & xml_attribute(item 1 of x, item 2 of x)
     end repeat
     if the_contents is "" then
          set the_result to the_indent & "<"<">" & return & the_contents & the_indent & "</""
     else
          return " " & the_label & "=\"" & xmlescape(thevalue) & "\""
     end if
end xml_attribute
on xmlescape(thestring)
     set the_string to the_string as string
     if (the offset of eof_character in the_string) > 0 then
          return eofavoider(thestring)
     else
          return do shell script ("perl -e 'my $a = $ARGV[0]; $a =~ s/&/&/g; $a =~ s/</</g; $a =~ s/>/>/g; $a =~ s/\"/"/g; while ( $a =~ m/^(.)([\x01-\x1F])(.)$/s ) { $a = $1 . \"&#\" . ord($2) . \"" . $3; } print $a;' " & the quoted form of the_string)
     end if
end xml_escape
on eofavoider(thestring)
     if the_string is eof_character then
          return "&#0;"
     else
          set the_offset to the offset of eof_character in the_string
          if the_offset is 0 then
               return xmlescape(thestring)
          else
               if the_offset is 1 then
                    return "&#0;" & xml_escape(text 2 through -1 of the_string)
               else
                    return xml_escape(text 1 through (the_offset - 1) of the_string) & eof_avoider(text the_offset through -1 of the_string)
               end if
          end if
     end if
end eof_avoider
on getpermissions_info(theitem)
     return the paragraphs of (do shell script ("perl -e 'my @a = lstat($ARGV[0]); my @u = getpwuid($a[4]); my @g = getgrgid($a[5]); printf \"%d\\n%04o\\n%s\\n%d\\n%s\\n%d\", ( ( -r $ARGV[0] ) ? ( 1 ) : ( 0 ) ), $a[2] & 07777, $u[6], $u[2], $g[0], $g[2];' " & the quoted form of (the POSIX path of the_item)))
end getpermissionsinfo

Similar Messages

  • Can Time Machine back up a second external hard drive that is attached via usb to a Time Capsule?

    Can Time Machine back up a second external hard drive that is attached via usb to a Time Capsule?
    I have a iMac with 10.7.4

    I want to back up the data on the external Hard Drive that is attached to the Time Capsule to the Tim Capsule using Time Machine.
    Thanks for the clarification.  Unfortunately, that will not work.  You will need to connect the drive directly to your Mac if you want Time Machine to backup the drive to the Time Capsule.

  • Get my Root's Hard Drive name through CLI (or Applescript)

    How do I retrieve the current name of my hard drive through the command line? It needs to be in a way that will allow me to easily parse it. I first tried this:
    $ ls -l /Volumes/ | grep -E '> /$'
    lrwxr-xr-x 1 root admin 1 Feb 2 17:25 demoive HD -> /
    which is pretty close, except for removing all the other stuff would be tricky (due to all the variations that could occur in different scenarios). So then I tried the following:
    $ diskutil info -plist / | grep '<key>VolumeName</key>' -A 1 | tail -n 1
    <string>demoive HD</string>
    which is more robust in my mind and totally works, however, it causes my optical drive make the little noise indicating that it's checking to see if I have a disk...and that sort of thing won't suffice for what I need (both because of the noise and delay of ~1.5 seconds).
    If someone knows of a way through AppleScript, that would work too as I can use the 'osascript' command via the command line.
    Cheers.

    Three AppleScript examples:
    osascript -e '"/" as POSIX file' | sed -e 's/:$//'
    osascript -e 'tell app "Finder" to get name of startup disk'
    osascript -e 'item 1 of (list disks)'
    If you want to avoid disktool (because it's deprecated) and also want to avoid AppleScript (bacause it's slow), another possibility is something like
    #!/bin/zsh
    cd /Volumes
    for d in *(@-/) # use * for bash
    do
    if [ "$(readlink "$d")" = '/' ]; then echo $d; exit; fi
    done

  • I have new hard drive in macbook pro(08) and have SATA cable with external power source to old hard drive (10.5.8)via. USB port and newer drive(10.6.8) will not recognize older drive..Do I need to partition newer drive with older disk to recover data?

    I have new HD 750GB Hybrid in 2008 Macbook Pro 17" w/ Snow Leopard 10.6.8  connected to old Hard drive(250GB that had 10.5.8 on it at time of failure) via SATA cable to USB port with external power source.. Computer not acknowledging old HD at all in Disk Utility or otherwise (that I'm aware of)..Do I need to partition New HD and load old(10.5.8) onto partition to recognize older drive for data recovery? Thanks Wayno08

    You do not need to load 10.5.8 onto your new drive in order for a 10.6.8 system to see the contents of a 10.5.8 system.
    You might want to check out the hard drive troubleshooting bootk in the downloads section of this web site:
    http://scsc-online.com
    They also sell a product named Phoenix that can do OS extraction  and volume copying/cloning, but to be honest I don't know if it's appropriate in this case.
    I would suggest the following:
    Open up Terminal.app (under utilities) and type "diskutil list" without the quotes. This is the command line version of Disk Utility. If the external drive doesn't show up at all, then it's likely not connected properly, not getting power, or just plain dead. If it shows up with only a devce name like disk0s16 but no volume it means the drive is seen, the OS just can't make sense of it.
    Assuming the drive shows up, I would try to boot off the original installl disks for the system and run Disk Utility from that. I'm assuming the drive will show up. You'll want to select the option to repair the drive and then perform the option to repair the permissions.
    If the unit isn't showing up, as per step 1, try a different USB port. More importantly with your unit, try it on another side of the unit if possible. If you read the book I referenced above, some of those units have I/O boards that are separated from the logic board. If the cable from the logic board to the I/O card goes bad or has problems, which isn't all that uncommon, some or all of the ports on the I/O card may appear to be bad as well. If you use a USB port on another side, it would be routing out of a completely different I/O path, so that's a potential problem.
    If the drive is only seen with a device name such as disk0s16, it's likely either the index files are corrupt beyond Disk Utility's ability to see them. The  only thing that I think would help would be a product named DIsk Warrior, but I can't guarantee that.
    Disk Warrior can be found at:
    http://www.alsoft.com/diskwarrior/
    The company that I linked in the first link above also makes a product named Scannerz that does HD and system testing. The Scannerz/Disk Warrior combination make a good pair because the complement each other....Scannerz does what Disk Warriror can't and Disk Warrior does what Scannerz can't. However, at this point I'm not too sure getting a tool like Scannerz would be of much use because it sounds like the  damage has already been done.
    Let us know what happens.

  • External hard Drive will not mount via firewire tpo my Powerbook G4

    I have a Powerbook G4 1.5, 2 Gb Ram and an 80 Gb Hard Drive. Well my problem is, I went and purchased a Western Digital External Hard Drive. The box states that this hard drive is compatible for both Windows and Mac. But for some reason I can't get the external hard drive to mount via the firewire. However it will mount by using the USB.
    So can someone please provide some troubleshooting tips on how I can get this external hard drive to mount?
    Thanks

    hi there,
    in your case, your drive is probably bad because the copy was interrupted. your hard drive may be finished, but more likely, just the file structure is damaged and/or you have bad sectors.
    you have a few options:
    *if you don't need the data back:*
    • see if the drive appears in disk utility and try to erase/reformat (make sure to zero out data to avoid bad sectors)
    • if it doesn't appear, try a pc. it won't recognize it, but it may allow you to reformat/initialize it. then, connect back into mac (which will recognize a pc formatted drive) and reformat as mac os x extended (journaled).
    *if you need the data back:*
    • try a program like data rescue II, file salvage, or boomerang data recovery first to recover the data
    • see if the drive appears in disk utility and try to repair disk
    • if that doesn't work, try disk warrior and/or drive genius
    • if you aren't successful, you may want to try a professional data recovery service (or me first, to ensure that you actually need someone as high tech as drive savers)
    • if you are successful and are able to recover the data, then erase the drive (zero out data) and then move the data back, to ensure you're working off a well formatted drive.
    fyi, if your computer freezes in the future, be sure to try appleoptionesc first and force quitting the problem application. if that doesn't work, try controloption+appleeject (shutdown) and/or optionappleeject (restart). if those doesn't work, in this situation, the next best move would probably have been turning off the power on the hard drive. if that doesn't unfreeze the system in a few minutes, then hold the power button.
    hope this helps,
    brian
    corewerkz/briancometa.com/

  • External Hard Drive Won't Mount Via USB

    I have a Western Digital (Model #WD2500...) Hard Drive that is about 3 years old. I initially set it up on a PowerBook running Mac OS 10.3.x. I have two newer laptops both running Snow Leopard, and neither will recognize my drive via USB 2.0.
    The weird part is that the drive will mount when connected via Firewire (400 in this case). My newest laptop is on of the new MacBook Pros and it only has Firewire 800. I'm guessing I could probably get a 400 to 800 Firewire cable, but it would be much easier to just use the USB 2.0 connection. Any idea why the drive won't mount over USB 2.0?
    I went to the Western Digital site, and there didn't appear to be any new drivers or firmware for this product. The drive seems to run perfectly well over the Firewire connection, so I don't see what the issue is with USB. The documentation that came with the drive indicates that it should work with USB. This is very baffling to me, so any help would be greatly appreciated.
    Thanks so much!!

    In most external drive enclosures that have both USB and Firewire interfaces, the Firewire interface is able to draw enough power to run the drive. Firewire can provide up to 45 watts and up to 30 volts of power per port (not all devices supply the full wattage; my MacBook model provides up to 8 watts). USB 2.0 and earlier can only provide 5 volts at 500 milliamps (up to 2.5 watts). Some newer laptop drives are at or under 500 milliamps, but just barely, and the enclosure itself needs some power.
    It sounds like the USB port on your enclosure is bad. Firewire is going to provide faster transfer rates anyway, and you don't have to bother with the power supply. Based on your comments, I suspect it still might be a bad power supply, or maybe it's not the right one for the drive. Those things are easy to mix up.
    If you're brave enough to crack the external drive open, what you'll find inside is a standard off-the-shelf hard disk drive, with either a SATA or PATA interface, in an enclosure. You can move the drive to a new enclosure easily.

  • I used an external hard drive for my backups via Time Capsule.  I bought a new computer and I want to transfer all my old fonts over to the new one but when I go into the Font Library from the hard drive backup but my downloaded fonts aren't there?

    I used an external hard drive to back up my computer using Time Capsule before I bought a new one.  I am slowly transferring information fromt he backup to my new computer and I want to transfer over my old font book.  When I go into the Font folder on the hard drive the only fonts that show up are the ones that came stock with the computer not any of the ones I have downloaded over time.  Could they be downloaded somewhere else?

    The answer to that would probably be "Yes." If you don't remember where your fonts were stored, you may want to search your backups for any of the font files you know the names to. See where that takes you.
    Ideally, Font Book and other font managers will temporarily store the fonts you "installed" into the System when you run the OS. When you shut down, etc. they are removed and reloaded on restart. The permanent place fonts reside is where you saved them when or after you downloaded them. I typically create a Resources folder on the root level of the computer and place a Fonts folder there. Then I install fonts from there, and they are available to all users on that iMac.
    Perhaps if you did not have that kind of a strategy, perhaps many of them are still in your Downloads folder?

  • Since installing Maverick my MacBook Air is no longer showing my external Hard drive, which I connect via USB.

    I know the external hard drive is working and the USB port works also.
    I have seen lots of complicated answers on here but nothing I can understand.
    Any help appriciated.
    Lesley

    The WD hard drive itself is probably fine, the enclosure has likely failed. WD externals are notorius for cheap enclosures failing. Try a different cable first. You can take the drive out and install it in a better enclosure, like one from OWC.
    http://eshop.macsales.com/

  • External hard drive is not mounting via hub

    Hi mates,
    I bought LaCie D2 Quadra external hard drive and when I connected it to LaCie Huby firewire port it would not mount at all, but when I connected the hard drive straight to my MacBooks firewire port it mounted nicely.
    what could be the problem that its not mounting with the hub?
    Message was edited by: tarts

    Just tested with USB and it works.
    oh.. just remembered that I sync my iPod through one of the Hubys fw ports, so I guess that ports are OK.
    Maybe I have a faulty fw cable?

  • Using a third party ext hard drive with time machine via aiport extreme

    Hi all,
    I have a 500GB external hard drive connected to my Airport Extreme Base Station 802.11n and so far have been unsuccessful in getting Time Machine to work with this.
    I have been told this is possible, but cannot figure out how to do it.
    _+*Any ideas?*+_
    We have one Macbook running 802.11n and one running 802.11g that is unable to be upgraded (as Core Duo, not Core 2 Duo).
    Thanks,
    tkoe

    tkoe wrote:
    Hi all,
    I have a 500GB external hard drive connected to my Airport Extreme Base Station 802.11n and so far have been unsuccessful in getting Time Machine to work with this.
    I have been told this is possible, but cannot figure out how to do it.
    _+*Any ideas?*+_
    We have one Macbook running 802.11n and one running 802.11g that is unable to be upgraded (as Core Duo, not Core 2 Duo).
    Thanks,
    tkoe
    TM suports WiFi backup only to TimeCapsule.
    There are unauthorized hacks to force TM to use WiFi links and you can search for them in these forums. I do not recommend a hack when it comes to preserving valuable data.

  • Can i use an external hard drive with time capsule via an airport extreme?

    i recently bought 750GB laCie hard drive... is it possible to use Time machine with the external HD plugged into my airport extreme?

    shanec805, wttdaWelcome to the discussion area!
    Remember that Time Capsule is a hardware device.
    Time Machine is a software feature of OS X 10.5.5.

  • WD Hard Drive doesn't work via Fire Wire to Mac OSX Lion or Mountain Lion.

    I have a 1 terrabyte WD Hard Drive that works perfectly fine connected to Snow Leopard but isn't even recognized by any Mac running Mountain lion!!!
    How do I fix this?????

    I agree with alkhater. From reading other posts about the issue (Googled "Western Digital hard drive not appearing in Disk Utility") it sounds like you need to update your driver. If you need help locating the correct driver, please let us know the exact hard drive that you have.

  • HT4818 Boot from laptop's Windows Hard Drive in Mac Pro via Boot Camp

    I have a work laptop that is on Windows 7.  It's a work hard drive so I don't want to mess with it (particularly as it's encrypted).  I basically want to use it on my Mac Pro rather than my piece of junk standard issue laptop when I'm working from home.
    What I would like to do is pull the drive out, put it in my Mac Pro and boot from it using Boot Camp.  Guidance I've seen so far talks about not being able to use an external drive but having to partition an internal drive.  However, if I've got everything on a separate drive (i.e. my laptop's drive), will this work?
    Thanks!

    Thanks for the quick (and no nonsense) response!

  • How to access external hard drive on the mac via airport TC

    I Just bought airport TC 2TB and completed setup. Wi-fi and wired connection are working properly. I can access the Airport TC 2 MB HD from mac mini  but   I haven't seen  that I plugged in 640 MB external samsung hard drive to USB port.
    File sharing is active on the Airport Utility
    Airport base station fw: 7.7.3
    Anybody has an experience how to solve this issue please share with me. Many thanks in advance

    The Samsung needs to be formatted the same as the Time Capsule.......in Mac OS Extended (Journaled).
    Is it?

  • Accessing my Time Capsule hard drive over the internet via iCloud doesn't work.

    Hi Everyone,
    I have an iCloud account and read recently, that it is possible to acces the hard drive of an Time Capsule over the internet, if "Back to my Mac" is activated on my MacBook an the Time Capsule.
    I updated the Time Capsule to Firmware Version 7.6.1 and the Airport Utility to version 6. Actually the Time Capsule HDD is displayes in Finder's Sidebar, when I'm using a forreign internet connection. But when I click on it an error message tells me that a connection to the server (I assume server=Time Capsule) cannot be established. Funnily enough I can access the HDD of my iMac at home.
    The Time Capsule network setting is "Bridge Mode" Since I can't deactivate the DNS functionality of my router/mode, an easybox 803 A, unfortunately which I cannot replace, because it is also used for hosting the telephone.
    Does anybody have an idea, where the problem could be? Wrong settings in the Time Capsule config or maybe the blocking by the router?
    Thank you all in advance,
    Markus
    Please consider, that I have absolutely no idea of networking.

    I don't know exactly how, but I got it working. I will try to explain, what I did.
    1. I used the easybox as DHCP-Server an set the TC to Bridge Mode.
    2. Then I gave the TC a fixed IP in the easbybox menu by using it's MAC-address (It seems that the address range has to be either 192.168.X.Y or 10.0.X.Y to make the TC accessable later).
    3. I made the TC a DHCP-Server (DHCP only, not also NAT). The IP addess range of the TC starts after it's own IP adress (10.0.0.111) and ends at (10.0.0.250). The IP range of the easybox starts with 10.0.0.1 (it's own) and end with the TC's (10.0.0.111).
    4. Then the Airport Utility told me that if I want to share an DHCP range the TC has to be set to a fixed IP setting, which I set up, leaving the IP-address 10.0.0.111 and the Router IP 10.0.0.1 (the easyboxs').
    5. Then it worked in my case. Since I don't even know what I did, I'm not shure if it workes under other circumstances.
    There are of course many variables. Such as the type of the router and the TC or the kind of the internet connection.

Maybe you are looking for