• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: OS X and RegEx Commands
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OS X and RegEx Commands


  • Subject: Re: OS X and RegEx Commands
  • From: John Cochrane <email@hidden>
  • Date: Tue, 2 Dec 2003 22:49:12 +1100

On Tuesday, December 2, 2003, at 09:45 AM, Walter Ian Kaye wrote:

Anyone got a script to create .dmg.gz files?

I'll echo that plea. It would good to enable file compression via Applescript without reliance on Stuffit.

In a previous posting "compress with resource forks" last August Jean-Baptiste LE STANG contributed the following script. I would prefer it did not rely on Satimage Osax (sorry Emmanuel).


Here is my script (requires Satimage OSAX), YOu just have to select the files you want to compress (they must be in the same directory)
The script, is not yet finished but it works

Has it been finished since Jean-Baptiste?


@+ JB

tell application "Finder"
activate
set myRecord to (display dialog "Enter a name for your archive : " default answer "")
set archiveName to text returned of myRecord
set button to button returned of myRecord
set selectedFiles to navchoose object
set totalSize to 0
repeat with x in selectedFiles
set totalSize to totalSize + (size of (get info for (x as alias)))
end repeat

set archiveSize to (round 1.25 * totalSize / (1024 * 1024)) --125 % of the original size

if archiveSize < 5 then set archiveSize to 5

if archiveName is not "" and button is not false then
my createDiskImage(archiveName, selectedFiles, archiveSize)
end if
display dialog "Archive created"
end tell

on createDiskImage(thisName, thooseFiles, totalSize)
try
set AppleScript's text item delimiters to ""
set myCommand to "hdiutil create -size " & totalSize & "m ~/Desktop/" & thisName
do shell script myCommand
do shell script "hdid -nomount ~/Desktop/" & thisName & ".dmg"
set diskList to paragraphs of (do shell script "ls /dev/ | grep 'disk' | awk '{print $1}'")
set itemCount to count diskList
set myDiskName to item (itemCount - 2) of diskList
set myCommand to "newfs_hfs -v " & thisName & " /dev/" & myDiskName
do shell script myCommand
set diskname to getRealDisk(myDiskName)
set myCommand to "hdiutil detach " & diskname
do shell script myCommand
set myCommand to "hdid ~/Desktop/" & thisName & ".dmg"
do shell script myCommand
repeat with x in thooseFiles
tell application "Finder"
set currentDirectory to quoted form of POSIX path of ((container of (x as alias)) as alias)
set fileName to (name of (x as alias))
end tell

set myCommand to "cd " & currentDirectory & ";" & "/Developer/Tools/CpMac -r -p '" & fileName & "' /Volumes/" & thisName
do shell script myCommand

end repeat
set myCommand to "hdiutil detach " & diskname
do shell script myCommand
set myCommand to "gzip -c ~/Desktop/" & thisName & ".dmg > ~/Desktop/" & thisName & ".tgz"
do shell script myCommand
on error errmsg
display dialog errmsg
end try
end createDiskImage

on getRealDisk(thisDisk)
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "r"
set realDiskName to text item 2 of thisDisk
set AppleScript's text item delimiters to "s2"
set realDiskName to text item 1 of realDiskName
set AppleScript's text item delimiters to oldTID
return realDiskName
end getRealDisk



John
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: OS X and RegEx Commands
      • From: Jean-Baptiste <email@hidden>
References: 
 >Re: OS X and RegEx Commands (From: Walter Ian Kaye <email@hidden>)

  • Prev by Date: Re: Satimage OSAX request
  • Next by Date: Re: Telling remote computer to "do shell script"
  • Previous by thread: Re: OS X and RegEx Commands
  • Next by thread: Re: OS X and RegEx Commands
  • Index(es):
    • Date
    • Thread