hdiutil打包dmg

  • 先创建一个UDRW格式的DMG,然后attach。
  • AppScrip设置窗口大小、app位置,背景图片。
  • detach DMG;
  • 转换格式为UDBZ
  • #项目路径 setEnv设置
    #WORKSPACE="xx"
    dmgSource_path="${WORKSPACE}/DMG"
    #挂载后显示的名称
    volname="XX"
    #.app和Application替身复制到的地方
    sourceFolder_path="${dmgSource_path}/dmgFolder"
    #背景图片名
    backgroundPictureName="bg_install.png"
    #背景图路径 setEnv设置
    #backgroundPicture_path="${WORKSPACE}/xx/${backgroundPictureName}"
    #.app名称 setEnv设置
    #applicationName="xx.app"
    #临时dmg
    tmpDMG_path="tmp.dmg"
    #最终dmg路径 setEnv设置
    #finalDMG_path="${dmgSource_path}/xx.dmg"
    #图片保存的位置,在sourceFolder_path内,加.代表隐藏
    backgroundFolder_path="${sourceFolder_path}/.background"
    #复制过来的app原位置 setEnv设置
    #app_source_path="${WORKSPACE}/build/Release/xx.app"
    #app复制后的位置
    app_final_path="${sourceFolder_path}/${applicationName}"
    #Applications替身位置
    application_path="${sourceFolder_path}/Applications"
    
    cd ${WORKSPACE}
    
    function prepare {
      rm -r ${finalDMG_path}
    
      #创建目录
      rm -r $dmgSource_path
      mkdir -p $dmgSource_path
    
      rm -r $sourceFolder_path
      mkdir -p $sourceFolder_path
    
      rm -r $tmpDMG_path
    
      #创建background_path
      rm -r $backgroundFolder_path
      mkdir -p $backgroundFolder_path
    
      #复制背景图到background_path
      cp -r $backgroundPicture_path "${backgroundFolder_path}/${backgroundPictureName}"
    
      #复制App到目录
      echo "---------${app_source_path}--------------${app_final_path}-----------"
      #有替身的不能直接-r,不然会报替身替换成源文件,导致体积过大
      cp -a $app_source_path $app_final_path
    
      #制作Applications替身,放到sourceFolder_path
      ln -s /Applications/ $application_path
    }
    
    function appleScript {
      echo '
      tell application "Finder"
       tell disk "'${volname}'"
          open
          set current view of container window to icon view
          set toolbar visible of container window to false
          set statusbar visible of container window to false
          set the bounds of container window to {400, 100, 950, 470}
          set theViewOptions to the icon view options of container window
          set arrangement of theViewOptions to not arranged
          set icon size of theViewOptions to 128
          set background picture of theViewOptions to file ".background:'${backgroundPictureName}'"
    #      make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
          set position of item "'${applicationName}'" of container window to {125, 160}
          set position of item "Applications" of container window to {447, 160}
          set position of item ".background" of container window to {447, 1000}
          set position of item ".fseventsd" of container window to {447, 1000}
          update without registering applications
          close
       end tell
      end tell
    ' | osascript
    }
    
    function removeFiles {
      rm -r $tmpDMG_path
      rm -r $sourceFolder_path
      rm -r $dmgSource_path
    
    }
    
    function detachDMG {
      hdiutil detach -force "/Volumes/${volname}"
    }
    
    function main {
      prepare
      detachDMG
      hdiutil create -srcdir $sourceFolder_path -volname ${volname} -format UDRW "${tmpDMG_path}"
      hdiutil attach $tmpDMG_path
      appleScript
      detachDMG
      hdiutil convert "${tmpDMG_path}" -format UDBZ -o "${finalDMG_path}"
      removeFiles
    }
    
    main

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Python程序打包dmg文件,可以使用以下步骤: 1. 安装py2app 在命令行中输入以下命令来安装py2app: ``` pip install py2app ``` 2. 创建setup.py文件 在Python程序的根目录下创建一个名为setup.py的文件,并添加以下代码: ```python from setuptools import setup APP = ['main.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': True, 'plist': { 'CFBundleName': 'My Application', 'CFBundleDisplayName': 'My Application', 'CFBundleGetInfoString': 'My Application v1.0', 'CFBundleIdentifier': 'com.example.myapp', 'CFBundleVersion': '1.0.0', 'CFBundleShortVersionString': '1.0', 'LSUIElement': True, }, 'packages': ['wx', 'os', 'sys'], } setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], ) ``` 这个文件定义了程序的名称、版本、标识符等信息,并将需要的Python包列为依赖项。 3. 打包程序 在命令行中输入以下命令来打包程序: ``` python setup.py py2app ``` 这将创建一个名为dist的文件夹,其中包含打包好的程序。 4. 创建dmg文件 使用以下命令来创建dmg文件: ``` hdiutil create -srcfolder dist/MyApplication.app -volname "My Application" -format UDZO -ov -o MyApplication.dmg ``` 这将在当前目录中创建一个名为MyApplication.dmgdmg文件,其中包含打包好的程序。 5. 完成 现在你已经成功地将Python程序打包成了dmg文件。你可以将该文件分享给其他人,他们可以直接在Mac上安装并使用该程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值