« [Printer]余白0のppdsをダウンロード(bash版) | トップページ | [Printer]PPDから仮想プリンタ作成(bash版) »

[Printer]余白0のppdsをダウンロード(as版)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

#############################
###AcrobatPPDの有無を確認
#############################
set ocidUserPathArray to (appFileManager's URLsForDirectory:(refMe's NSUserDirectory) inDomains:(refMe's NSLocalDomainMask))
set ocidUserPathURL to ocidUserPathArray's objectAtIndex:0
set ocidPPDFilePathURL to ocidUserPathURL's URLByAppendingPathComponent:"Shared/Library/Printers/PPDs/Contents/Resources/Acrobat/ADPDF9J.PPD" isDirectory:true
set boolFileExists to (appFileManager's fileExistsAtPath:(ocidPPDFilePathURL's |path|()) isDirectory:false)
set ocidSaveDirPathURL to ocidUserPathURL's URLByAppendingPathComponent:"Shared/Library/Printers/PPDs/Contents/Resources/Acrobat" isDirectory:true
############PPDファイルの有無チェック
if boolFileExists is true then
log "PPDはインストール済み"
  set strPPDsFilePath to ocidPPDFilePathURL's |path|() as text
  
else
  ########################
  ###無い場合はダウンロード
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
  set listResults to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #### ダウンロード
  set strZipFileURL to "https://quicktimer.cocolog-nifty.com/icefloe/files/acrobat.zip"
  set ocidZipFilePath to (refMe's NSString's stringWithString:(strZipFileURL))
  set ocidZipFilePathURL to refMe's NSURL's alloc()'s initWithString:(ocidZipFilePath)
  set ocidZipData to refMe's NSData's dataWithContentsOfURL:(ocidZipFilePathURL)
  ##保存
  set ocidTempDirPathURL to appFileManager's temporaryDirectory()
  set ocidSaveZipFilePathURL to ocidTempDirPathURL's URLByAppendingPathComponent:"acrobatppds.zip" isDirectory:false
  set boolResults to ocidZipData's writeToURL:(ocidSaveZipFilePathURL) atomically:true
  
  if boolResults is false then
return "ダウンロードに失敗しました"
  end if
  #### 解凍
  set strZipFilePathURL to ocidSaveZipFilePathURL's |path|() as text
  set strSaveDirPathURL to (ocidSaveDirPathURL's URLByDeletingLastPathComponent())'s |path|() as text
  try
    set theComandText to ("/usr/bin/ditto -xk \"" & strZipFilePathURL & "\" \"" & strSaveDirPathURL & "\"") as text
do shell script theComandText
  end try
end if

set strDirPath to (ocidSaveDirPathURL's |path|()) as text
set aliasFilePath to (ocidSaveDirPathURL's absoluteURL()) as alias
###開く
set ocidSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolSelectFileResults to ocidSharedWorkspace's selectFile:(strPPDsFilePath) inFileViewerRootedAtPath:(strDirPath)
if boolSelectFileResults = false then
  tell application "Finder"
    set refNewWindow to make new Finder window
    set target of refNewWindow to aliasFilePath
  end tell
  
end if

|

« [Printer]余白0のppdsをダウンロード(bash版) | トップページ | [Printer]PPDから仮想プリンタ作成(bash版) »

Admin Printer」カテゴリの記事