Twitter

twitter用画像生成 9種類の画像の合成




ダウンロード - tw9to4images.zip





AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# 試してみたい場合は
005# https://quicktimer.cocolog-nifty.com/icefloe/files/tw9to4images.zip
006# ↑をダウンロードして試してください
007# com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "UniformTypeIdentifiers"
012use framework "AppKit"
013use scripting additions
014
015property refMe : a reference to current application
016
017set appFileManager to refMe's NSFileManager's defaultManager()
018
019####################
020#基本パス
021set aliasPathToMe to (path to me) as alias
022tell application "Finder"
023  set aliasContainerDirPath to (container of aliasPathToMe) as alias
024end tell
025#コンテナ
026set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
027set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
028set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
029set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:false)
030#保存先フォルダ
031set ocidSaveDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("FinishImage") isDirectory:(true)
032#マテリアルフォルダ
033set ocidMaterialDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("01_Material") isDirectory:(true)
034#メインイメージフォルダ
035set ocidMainDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("02_MainImage") isDirectory:(true)
036
037####################
038#コンテンツ収集 1階層のみ
039set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
040set ocidKeyArray to refMe's NSArray's arrayWithArray:({(refMe's NSURLPathKey), (refMe's NSURLIsDirectoryKey), (refMe's NSURLIsSymbolicLinkKey)})
041set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidMaterialDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
042if (item 2 of listResponse) = (missing value) then
043  set ocidSubPathArray to (item 1 of listResponse)
044else if (item 2 of listResponse) ≠ (missing value) then
045  set strErrorNO to (item 2 of listResponse)'s code() as text
046  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
047  refMe's NSLog("■:" & strErrorNO & strErrorMes)
048  return "エラーしました" & strErrorNO & strErrorMes
049end if
050#ソート
051set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(yes) selector:("localizedStandardCompare:")
052set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
053set ocidSortedArray to ocidSubPathArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
054#素材のURL
055(*
056set ocidTopImageURL to ocidMaterialDirPathURL's URLByAppendingPathComponent:("1@1920x1080.png") isDirectory:(false)
057set ocidBottomImageURL to ocidMaterialDirPathURL's URLByAppendingPathComponent:("2@1920x1080.png") isDirectory:(false)
058*)
059# メインになるイメージ
060set ocidMidImageURL to ocidMainDirPathURL's URLByAppendingPathComponent:("main@1920x1080.jpg") isDirectory:(false)
061
062####################
063#4回繰り返し
064set numCntImageNO to 0 as integer
065repeat with itemNo from 1 to (4) by 1
066  #上下画像の取得
067  set numTopImageNO to (numCntImageNO) as integer
068  set numBottomImageNo to (numTopImageNO + 1) as integer
069  #URLに
070  set ocidTopImageURL to (ocidSortedArray's objectAtIndex:(numTopImageNO))
071  set ocidBottomImageURL to (ocidSortedArray's objectAtIndex:(numBottomImageNo))
072  set numCntImageNO to (numBottomImageNo + 1) as integer
073  #保存ファイルURLを生成
074  set numSaveImageNo to itemNo as integer
075  set strSaveFileName to (numSaveImageNo & "@960x1620.png") as text
076  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false))
077  
078  ####################
079  #出力用のマージ画像
080  set numSetPxWidth to (960) as integer
081  set numSetPxHeight to (1620) as integer
082  set ocidSaveImagePixelsSize to refMe's NSMakeSize(numSetPxWidth, numSetPxHeight)
083  # samplesPerPixel
084  set intSPP to 4 as integer
085  # bitsPerSample
086  set intBPS to 8 as integer
087  # bytesPerRow
088  set intBPR to 0 as integer
089  # bitsPerPixel
090  set intBPP to 32 as integer
091  # RGB系のカラースペース
092  set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
093  # アルファあり
094  set ocidBitmapFormat to refMe's NSAlphaFirstBitmapFormat
095  #出力ピクセルサイズのブランクイメージ
096  set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSetPxWidth) pixelsHigh:(numSetPxHeight) bitsPerSample:(intBPS) samplesPerPixel:(intSPP) hasAlpha:(true) isPlanar:(false) colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(intBPP))
097  ####################
098  #ArtBord
099  refMe's NSGraphicsContext's saveGraphicsState()
100  #Context
101  set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
102  #生成された画像でNSGraphicsContext初期化
103  (refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
104  #色を個別に指定する場合 値は0が暗 1が明
105  set ocidSetColor to (refMe's NSColor's colorWithSRGBRed:(1.0) green:(1.0) blue:(1.0) alpha:(0.0))
106  ocidSetColor's |set|()
107  #画像生成
108  set ocidSaveImageRect to refMe's NSMakeRect(0, 0, numSetPxWidth, (numSetPxHeight))
109  refMe's NSRectFill(ocidSaveImageRect)
110  ####画像作成終了
111  refMe's NSGraphicsContext's restoreGraphicsState()
112  
113  ####################
114  #上部画像読み込み
115  set ocidTopImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidTopImageURL))
116  set ocidImageSize to ocidTopImage's |size|()
117  set numPtWidth to ocidImageSize's width
118  set numPtHeigh to ocidImageSize's height
119  set ocidTopImageRepArray to ocidTopImage's representations()
120  set ocidTopImageRep to ocidTopImageRepArray's firstObject()
121  set numPixelsWidth to ocidTopImageRep's pixelsWide()
122  set numPixelsHeight to ocidTopImageRep's pixelsHigh()
123  set ocidPixelsSize to refMe's NSMakeSize(numPixelsWidth, numPixelsHeight)
124  (ocidTopImageRep's setSize:(ocidPixelsSize))
125  
126  ####################
127  #上部マージ
128  refMe's NSGraphicsContext's saveGraphicsState()
129  #Context
130  set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
131  #NSGraphicsContext初期化
132  (refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
133  #NSCompositeSourceOver
134  set ocidFromRect to refMe's NSMakeRect(0, 0, numPixelsWidth, numPixelsHeight)
135  set ocidDrawRect to refMe's NSMakeRect(0, 1080, 960, 540)
136  #
137  set ocidOption to (refMe's NSCompositingOperationSourceOver)
138  #
139  (ocidTopImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
140  #画像作成終了
141  refMe's NSGraphicsContext's restoreGraphicsState()
142  
143  ####################
144  #下部部画像読み込み
145  set ocidBottomImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidBottomImageURL))
146  set ocidImageSize to ocidBottomImage's |size|()
147  set numPtWidth to ocidImageSize's width
148  set numPtHeigh to ocidImageSize's height
149  set ocidBottomImageRepArray to ocidBottomImage's representations()
150  set ocidBottomImageRep to ocidBottomImageRepArray's firstObject()
151  set numPixelsWidth to ocidBottomImageRep's pixelsWide()
152  set numPixelsHeight to ocidBottomImageRep's pixelsHigh()
153  set ocidPixelsSize to refMe's NSMakeSize(numPixelsWidth, numPixelsHeight)
154  (ocidBottomImageRep's setSize:(ocidPixelsSize))
155  
156  ####################
157  #下部マージ
158  refMe's NSGraphicsContext's saveGraphicsState()
159  #Context
160  set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
161  #NSGraphicsContext初期化
162  (refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
163  #NSCompositeSourceOver
164  set ocidFromRect to refMe's NSMakeRect(0, 0, numPixelsWidth, numPixelsHeight)
165  set ocidDrawRect to refMe's NSMakeRect(0, 0, 960, 540)
166  #
167  set ocidOption to (refMe's NSCompositingOperationSourceOver)
168  #
169  (ocidBottomImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
170  #画像作成終了
171  refMe's NSGraphicsContext's restoreGraphicsState()
172  
173  ####################
174  #メイン画像読み込み
175  set ocidMidImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidMidImageURL))
176  set ocidImageSize to ocidMidImage's |size|()
177  set numPtWidth to ocidImageSize's width
178  set numPtHeigh to ocidImageSize's height
179  set ocidMidImageRepArray to ocidMidImage's representations()
180  set ocidMidImageRep to ocidMidImageRepArray's firstObject()
181  set numPixelsWidth to ocidMidImageRep's pixelsWide()
182  set numPixelsHeight to ocidMidImageRep's pixelsHigh()
183  set ocidPixelsSize to refMe's NSMakeSize(numPixelsWidth, numPixelsHeight)
184  (ocidMidImageRep's setSize:(ocidPixelsSize))
185  
186  ####################
187  #メインマージ
188  refMe's NSGraphicsContext's saveGraphicsState()
189  #Context
190  set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
191  #NSGraphicsContext初期化
192  (refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
193  #NSCompositeSourceOver
194  #メインのイメージのどのRECTを取得するか?
195  if itemNo is 1 then
196    #1
197    set ocidFromRect to refMe's NSMakeRect(0, 540, 960, 540)
198  else if itemNo is 2 then
199    #2
200    set ocidFromRect to refMe's NSMakeRect(960, 540, 960, 540)
201  else if itemNo is 3 then
202    #3
203    set ocidFromRect to refMe's NSMakeRect(0, 0, 960, 540)
204  else if itemNo is 4 then
205    #4
206    set ocidFromRect to refMe's NSMakeRect(960, 0, 960, 540)
207  end if
208  #
209  set ocidDrawRect to refMe's NSMakeRect(0, 540, 960, 540)
210  #
211  set ocidOption to (refMe's NSCompositingOperationSourceOver)
212  #
213  (ocidMidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:1.0 respectFlipped:true hints:(missing value))
214  #画像作成終了
215  refMe's NSGraphicsContext's restoreGraphicsState()
216  
217  ####################
218  #保存オプション
219  set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
220  (ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
221  (ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))
222  ##保存
223  set ocidNSInlineData to (ocidArtBoardRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(ocidProperty))
224  set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) atomically:true)
225  
226  
227  
228end repeat
229
230
231####################
232#
233set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
234set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
235
236
237
238
AppleScriptで生成しました

|

twitter投稿用画像3分割(仮)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
1つの画像を16:9の4分割します
サイズによって切り取られる部分があります
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()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
#############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
  # tell application id "com.apple.appkit.xpc.openAndSavePanelService" to activate
else
  tell current application to activate
end if
set listUTI to {"public.image"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
#
set ocidFileName to ocidFilePathURL's lastPathComponent()
set strBaseFileName to (ocidFileName's stringByDeletingPathExtension()) as text
#
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasSaveDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
############

set strMes to "保存先フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasSaveDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

############
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)
if (item 2 of listData) ≠ (missing value) then
log (item 2 of listData)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
else
  set ocidData to (item 1 of listData)
end if
############
#イメージに変換
set ocidImage to refMe's NSImage's alloc()'s initWithData:(ocidData)
#BmpRepに変換
set ocidImageRepArray to ocidImage's representations()
set ocidImageRep to ocidImageRepArray's firstObject()
#ptサイズ
set ocidSize to ocidImageRep's |size|()
set numWpt to ocidSize's width
set numHpt to ocidSize's height
#pxサイズ
set numWpx to ocidImageRep's pixelsWide()
set numHpx to ocidImageRep's pixelsHigh()
#解像度
set numResolution to (numWpx / numWpt) as number
#BmpRepを72ppiにしておく
set ocidSetSize to refMe's NSMakeSize(numWpx, numHpx)
ocidImageRep's setSize:(ocidSetSize)

############
#画像1セルサイズを計算
if numWpx ≥ numHpx then
log "横長か正方形画像"
  set numAspectH to (numHpx / 18) as number
  set numAspectW to (numAspectH * 16) as number
  if (numAspectW * 2) ≥ numWpx then
log "上下に余白でCROP"
    set numAspectW to (numWpx / 32) as number
    set numSelW to (numAspectW * 16) as number
    set numSelH to (numAspectW * 9) as number
    set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
    set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  else
log "左右に余白でCROP"
    set numSelW to (numAspectH * 16) as number
    set numSelH to (numAspectH * 9) as number
    set numMarginLeft to ((numWpx - (numAspectH * 32)) / 2) as number
    set numMarginTop to 0 as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  end if
  
else if numWpx < numHpx then
log "縦長"
  set numAspectW to (numWpx / 32) as number
  set numSelW to (numAspectW * 16) as number
  set numSelH to (numAspectW * 9) as number
  set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
  set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
  set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
end if



repeat with itemIntNo from 1 to 3 by 1
  ################左下
  ##出力用REP
  if itemIntNo is 1 then
    set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSelW) pixelsHigh:(numSelH * 2) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  else
    set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSelW) pixelsHigh:(numSelH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  end if
  
  ##処理開始
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ##仕上がり寸法RECT(ペースト位置)
  if itemIntNo is 1 then
    set ocidPasteRect to {origin:{x:0, y:0}, |size|:{width:(numSelW), height:(numSelH * 2)}}
  else
    set ocidPasteRect to {origin:{x:0, y:0}, |size|:{width:(numSelW), height:(numSelH)}}
  end if
  ##元データのRECT(コピー位置)
  #セル毎のコピー位置
  if itemIntNo is 1 then
    set ocidCopyRect to {origin:{x:(numMarginLeft), y:(numMarginTop)}, |size|:{width:(numSelW), height:(numSelH * 2)}}
  else if itemIntNo is 2 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:(numMarginTop + numSelH)}, |size|:{width:(numSelW), height:(numSelH)}}
  else if itemIntNo is 3 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:numMarginTop}, |size|:{width:(numSelW), height:(numSelH)}}
  end if
  ##合成
(ocidImageRep's drawInRect:(ocidPasteRect) fromRect:(ocidCopyRect) operation:(refMe's NSCompositingOperationSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##処理終了
ocidGraphicsContext's restoreGraphicsState()
  ###変換オプション
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  #PNG変換でデータにする
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  ##########################
  ##保存
  #ファイル名
  if itemIntNo is 1 then
    set strSaveFileName to (strBaseFileName & "_1_L") as text
  else if itemIntNo is 2 then
    set strSaveFileName to (strBaseFileName & "_2_RT") as text
  else if itemIntNo is 3 then
    set strSaveFileName to (strBaseFileName & "_3_RB") as text
  end if
  #保存パス
  set ocidBaseSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false))
  set ocidSaveFilePathURL to (ocidBaseSaveFilePathURL's URLByAppendingPathExtension:("png"))
  #保存
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  end if
end repeat

###保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
ocidConfig's setHides:(refMe's NSNumber's numberWithBool:false)
##
(appSharedWorkspace's openURL:(ocidSaveDirPathURL) configuration:(ocidConfig) completionHandler:(missing value))




|

twitter投稿用画像4分割


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
1つの画像を16:9の4分割します
サイズによって切り取られる部分があります
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()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
#############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
  # tell application id "com.apple.appkit.xpc.openAndSavePanelService" to activate
else
  tell current application to activate
end if
set listUTI to {"public.image"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
#
set ocidFileName to ocidFilePathURL's lastPathComponent()
set strBaseFileName to (ocidFileName's stringByDeletingPathExtension()) as text
#
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasSaveDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
############

set strMes to "保存先フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasSaveDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

############
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)
if (item 2 of listData) ≠ (missing value) then
log (item 2 of listData)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
else
  set ocidData to (item 1 of listData)
end if
############
#イメージに変換
set ocidImage to refMe's NSImage's alloc()'s initWithData:(ocidData)
#BmpRepに変換
set ocidImageRepArray to ocidImage's representations()
set ocidImageRep to ocidImageRepArray's firstObject()
#ptサイズ
set ocidSize to ocidImageRep's |size|()
set numWpt to ocidSize's width
set numHpt to ocidSize's height
#pxサイズ
set numWpx to ocidImageRep's pixelsWide()
set numHpx to ocidImageRep's pixelsHigh()
#解像度
set numResolution to (numWpx / numWpt) as number
#BmpRepを72ppiにしておく
set ocidSetSize to refMe's NSMakeSize(numWpx, numHpx)
ocidImageRep's setSize:(ocidSetSize)

############
#画像1セルサイズを計算
if numWpx ≥ numHpx then
log "横長か正方形画像"
  set numAspectH to (numHpx / 18) as number
  set numAspectW to (numAspectH * 16) as number
  if (numAspectW * 2) ≥ numWpx then
log "上下に余白でCROP"
    set numAspectW to (numWpx / 32) as number
    set numSelW to (numAspectW * 16) as number
    set numSelH to (numAspectW * 9) as number
    set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
    set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  else
log "左右に余白でCROP"
    set numSelW to (numAspectH * 16) as number
    set numSelH to (numAspectH * 9) as number
    set numMarginLeft to ((numWpx - (numAspectH * 32)) / 2) as number
    set numMarginTop to 0 as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  end if
  
else if numWpx < numHpx then
log "縦長"
  set numAspectW to (numWpx / 32) as number
  set numSelW to (numAspectW * 16) as number
  set numSelH to (numAspectW * 9) as number
  set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
  set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
  set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
end if

set numCntRepat to 1 as integer
repeat 4 times
  ################左下
  ##出力用REP
  set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSelW) pixelsHigh:(numSelH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  ##処理開始
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ##仕上がり寸法RECT(ペースト位置)
  set ocidPasteRect to {origin:{x:0, y:0}, |size|:{width:(numSelW), height:(numSelH)}}
  ##元データのRECT(コピー位置)
  #セル毎のコピー位置
  if numCntRepat is 1 then
    set ocidCopyRect to {origin:{x:(numMarginLeft), y:(numMarginTop + numSelH)}, |size|:{width:(numSelW), height:(numSelH)}}
  else if numCntRepat is 2 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:(numMarginTop + numSelH)}, |size|:{width:(numSelW), height:(numSelH)}}
  else if numCntRepat is 3 then
    set ocidCopyRect to {origin:{x:(numMarginLeft), y:numMarginTop}, |size|:{width:(numSelW), height:(numSelH)}}
  else if numCntRepat is 4 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:numMarginTop}, |size|:{width:(numSelW), height:(numSelH)}}
  end if
  ##合成
(ocidImageRep's drawInRect:(ocidPasteRect) fromRect:(ocidCopyRect) operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##処理終了
ocidGraphicsContext's restoreGraphicsState()
  ###変換オプション
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  #PNG変換でデータにする
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  ##########################
  ##保存
  #ファイル名
  if numCntRepat is 1 then
    set strSaveFileName to (strBaseFileName & "_1_LT") as text
  else if numCntRepat is 2 then
    set strSaveFileName to (strBaseFileName & "_2_RT") as text
  else if numCntRepat is 3 then
    set strSaveFileName to (strBaseFileName & "_3_LB") as text
  else if numCntRepat is 4 then
    set strSaveFileName to (strBaseFileName & "_4_RB") as text
  end if
  #保存パス
  set ocidBaseSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)
  set ocidSaveFilePathURL to ocidBaseSaveFilePathURL's URLByAppendingPathExtension:("png")
  #保存
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  end if
  set numCntRepat to numCntRepat + 1 as integer
end repeat

|

[com.microsoft.edgemac]前面のページのURLをtwitter.comに引用投稿


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# エッジで前面のページのURLをtwitter.comに引用投稿
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.microsoft.edgemac" as text
#####WINDOWチェック
tell application id strBundleID
  set numCntWindow to (count of every window) as integer
  if numCntWindow = 0 then
return "ウィンドウがありません"
  end if
end tell
tell application "Microsoft Edge"
activate
  tell front window
    tell active tab
      set strCurrentTabUrl to URL as text
      set strCurrentTabTitle to title as text
    end tell
  end tell
end tell
###区切り文字を入れて改行
set strSetTextValue to ("\n--\n" & strCurrentTabTitle) as text
set ocidSetTextValue to refMe's NSString's stringWithString:(strSetTextValue)

#######URLの基本的な部分
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
ocidURLComponents's setScheme:("https")
ocidURLComponents's setHost:("twitter.com")
ocidURLComponents's setPath:("/intent/tweet")
#クエリー部分
set ocidQueryItems to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("url") value:(strCurrentTabUrl)
ocidQueryItems's addObject:(ocidQueryItem)
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("text") value:(ocidSetTextValue)
ocidQueryItems's addObject:(ocidQueryItem)
ocidURLComponents's setQueryItems:(ocidQueryItems)
#テキストに戻して エッジに渡す
set ocidOpenURL to ocidURLComponents's |URL|()
set strOpenURL to ocidOpenURL's absoluteString() as text


###Chromeに渡す
tell application "Microsoft Edge"
activate
  tell front window
    set objNewTab to make new tab
    tell objNewTab to set URL to strOpenURL
  end tell
end tell

旧版はテキストとして扱う

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# エッジで前面のページのURLをtwitter.comに引用投稿
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.microsoft.edgemac" as text
#####WINDOWチェック
tell application id strBundleID
  set numCntWindow to (count of every window) as integer
  if numCntWindow = 0 then
return "ウィンドウがありません"
  end if
end tell

tell application "Microsoft Edge"
activate
  tell front window
    tell active tab
      set strCurrentTabUrl to URL as text
      set strCurrentTabTitle to title as text
    end tell
  end tell
end tell

###区切り文字を入れて改行
set strCurrentTabTitle to ("\n--\n" & strCurrentTabTitle) as text
###エンコードして
set strCurrentTabUrl to doUrlEncode(strCurrentTabUrl) as text
set strCurrentTabTitle to doUrlEncode(strCurrentTabTitle) as text
###送信用URLに整形して
set strBaseUrl to "https://twitter.com/intent/tweet?" as text
set strOpenUrl to ("" & strBaseUrl & "url=" & strCurrentTabUrl & "&text=" & strCurrentTabTitle & "") as text
###Chromeに渡す
tell application "Microsoft Edge"
activate
  tell front window
    set objNewTab to make new tab
    tell objNewTab to set URL to strOpenUrl
  end tell
end tell
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ######## 置換 %エンコードの追加処理
  ###置換レコード
  set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26", |$|:"%24"} as record
  ###ディクショナリにして
  set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:(recordPercentMap)
  ###キーの一覧を取り出します
  set ocidAllKeys to ocidPercentMap's allKeys()
  ###取り出したキー一覧を順番に処理
  repeat with itemAllKey in ocidAllKeys
    ##キーの値を取り出して
    set ocidMapValue to (ocidPercentMap's valueForKey:(itemAllKey))
    ##置換
    set ocidEncodedText to (ocidArgTextEncoded's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
    ##次の変換に備える
    set ocidArgTextEncoded to ocidEncodedText
  end repeat
  ##テキスト形式に確定
  set strTextToEncode to ocidEncodedText as text
  ###値を戻す
return strTextToEncode
end doUrlEncode

|

twitter投稿用

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

#!/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.6"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

tell application "Google Chrome"
  activate
  tell window 1
    tell active tab
      set strCurrentTabUrl to URL as text
      set strCurrentTabTitle to title as text
    end tell
  end tell
end tell

set strBaseUrl to "https://twitter.com/intent/tweet?"

set strCurrentTabTitle to ("\n--\n" & strCurrentTabTitle) as text

set strCurrentTabUrl to doUrlEncode(strCurrentTabUrl) as text
set strCurrentTabTitle to doUrlEncode(strCurrentTabTitle) as text

set strOpenUrl to ("" & strBaseUrl & "url=" & strCurrentTabUrl & "&text=" & strCurrentTabTitle & "") as text

tell application "Google Chrome"
  activate
  tell window 1
    set objNewTab to make new tab
    tell objNewTab to set URL to strOpenUrl
  end tell
end tell

on doUrlEncode(argString)
  set ocidStrings to refMe's NSString's stringWithString:(argString)
  set ocidCharacterSet to refMe's NSCharacterSet's URLPathAllowedCharacterSet()
  set ocidEncodedURL to ocidStrings's stringByAddingPercentEncodingWithAllowedCharacters:ocidCharacterSet
  set strEncodedURL to ocidEncodedURL as text
  return strEncodedURL as text
end doUrlEncode

|

[m3u]Twitterビデオダウンロード(ヘルパー)m4s用



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
(*

m3u8?variant_version=1
m3u8?container=fmp4

*)
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL

set objFileManager to objMe's NSFileManager's defaultManager()

####BaseURL
set strBaseURL to "https://video.twimg.com"

####クリップボードの内容をデフォルトに利用
tell application "Finder"
set strClipboardText to the clipboard as text
end tell
####コピーしているの前提で
set strDefaultAnswer to (strBaseURL & strClipboardText)
###ICONのパス
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ConnectToIcon.icns" as alias
###ダイアログ
set objResponse to (display dialog "URLを入力してください" with title "m3uファイル" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 10 without hidden answer)
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
error number -128
end if
if "OK" is equal to (button returned of objResponse) then
set strResponse to (text returned of objResponse) as text
else
log "エラーしました"
return "エラーしました"
error number -128
end if


###日付取得
###フォーマットは<http://nsdateformatter.com>参照
set strDateFormat to "yyyyMMddhhmmss" as text
set ocidForMatter to objMe's NSDateFormatter's alloc()'s init()
ocidForMatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidForMatter's setDateFormat:(strDateFormat)
set strDateText to (ocidForMatter's stringFromDate:(current date)) as text
####作成するダウンロードフォルダのパス
set strDirPath to ("/tmp/" & strDateText & "")
set objDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:objDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))
###エラー判定
if boolMakeNewFolder is false then
return "ダウンロードフォルダの作成に失敗しました"
end if
(*
テンポラリーファイルを/tmpに作る事で
次回の再起動時に自動的に削除されるメリットがあります
*)
####
##まずは m3u8ファイルをダウンロードします
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strResponse & "' -o '" & strDirPath & "/" & strDateText & ".m3u8'" as text
###コマンド実行
do shell script strCommandText

set strFilePath to "" & strDirPath & "/" & strDateText & ".m3u8"

####ドキュメントのパスをNSString
set ocidFilePath to objNSString's stringWithString:strFilePath
####ドキュメントのパスをNSURL
set ocidNSUrlPath to objNSURL's fileURLWithPath:ocidFilePath
####ファイル名
set ocidFileName to ocidNSUrlPath's lastPathComponent
####拡張子を除いたファイル名
set strPrefixName to (ocidFileName's stringByDeletingPathExtension) as text

##読み込み (テキスト)
set ocidReadM3Udata to objNSString's stringWithContentsOfFile:ocidFilePath

###改行でリスト化
set strReturn to "\n"
set ocidReadM3UdataArray to ocidReadM3Udata's componentsSeparatedByString:(strReturn)
###ダウンロードするテンポラリーファイルのナンバリング
set strFileNo to 1000 as number
###改行だけ繰返し
repeat with objReadM3UdataArray in ocidReadM3UdataArray
###テキストにして
set strReadM3UdataArray to objReadM3UdataArray as text
####EXT-X-MAP 部を最初に処理 初期化セクション
if strReadM3UdataArray starts with "#EXT-X-MAP" then
###ファイル番号カウントアップ
set strFileNo to strFileNo + 1 as number
set strMapPath to doReplace(strReadM3UdataArray, "#EXT-X-MAP:URI=", "")
set strMapPath to doReplace(strMapPath, "\"", "")
###URL整形
set strURL to (strBaseURL & strMapPath) as text
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".m4s'" as text
do shell script strCommandText
else if strReadM3UdataArray starts with "#" then
log "コメント行"
else if strReadM3UdataArray is "" then
log "空行"
else
#####コンテンツ部のダウンロード
###ファイル番号カウントアップ
set strFileNo to strFileNo + 1 as number
####ドキュメントのパスをNSURL
set ocidNSUrlReadM3UdataArray to (objNSURL's fileURLWithPath:objReadM3UdataArray)
####ファイル名
set ocidM3UFileName to ocidNSUrlReadM3UdataArray's lastPathComponent
####拡張子
set strM3UPrefixName to (ocidM3UFileName's pathExtension) as text
log strM3UPrefixName
### URL整形
set strURL to (strBaseURL & strReadM3UdataArray) as text
if strM3UPrefixName is "m4s" then
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".m4s'" as text
else if strM3UPrefixName is "ts" then
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".ts'" as text
end if
###コマンド実行
do shell script strCommandText
end if

end repeat
#####
(*
要は元のMP4だったりTSファイルをsplitしてある『だけ』なので
CATで結合できます。

*)
if strM3UPrefixName is "m4s" then
###ダウンロード終わったものをまとめる
do shell script "/bin/cat " & strDirPath & "/*m4s >> ~/Desktop/" & strPrefixName & ".mp4"
else if strM3UPrefixName is "ts" then
###ダウンロード終わったものをまとめる
do shell script "/bin/cat " & strDirPath & "/*ts >> ~/Desktop/" & strPrefixName & ".ts"
end if





to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace


#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
(*

m3u8?variant_version=1
m3u8?container=fmp4

*)
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL

set objFileManager to objMe's NSFileManager's defaultManager()

####BaseURL
set strBaseURL to "https://video.twimg.com"

####クリップボードの内容をデフォルトに利用
tell application "Finder"
set strClipboardText to the clipboard as text
end tell
####コピーしているの前提で
set strDefaultAnswer to (strBaseURL & strClipboardText)
###ICONのパス
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ConnectToIcon.icns" as alias
###ダイアログ
set objResponse to (display dialog "URLを入力してください" with title "m3uファイル" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 10 without hidden answer)
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
error number -128
end if
if "OK" is equal to (button returned of objResponse) then
set strResponse to (text returned of objResponse) as text
else
log "エラーしました"
return "エラーしました"
error number -128
end if


###日付取得
###フォーマットは<http://nsdateformatter.com>参照
set strDateFormat to "yyyyMMddhhmmss" as text
set ocidForMatter to objMe's NSDateFormatter's alloc()'s init()
ocidForMatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidForMatter's setDateFormat:(strDateFormat)
set strDateText to (ocidForMatter's stringFromDate:(current date)) as text
####作成するダウンロードフォルダのパス
set strDirPath to ("/tmp/" & strDateText & "")
set objDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:objDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))
###エラー判定
if boolMakeNewFolder is false then
return "ダウンロードフォルダの作成に失敗しました"
end if
(*
テンポラリーファイルを/tmpに作る事で
次回の再起動時に自動的に削除されるメリットがあります
*)
####
##まずは m3u8ファイルをダウンロードします
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strResponse & "' -o '" & strDirPath & "/" & strDateText & ".m3u'" as text
###コマンド実行
do shell script strCommandText

set strFilePath to "" & strDirPath & "/" & strDateText & ".m3u8"

####ドキュメントのパスをNSString
set ocidFilePath to objNSString's stringWithString:strFilePath
####ドキュメントのパスをNSURL
set ocidNSUrlPath to objNSURL's fileURLWithPath:ocidFilePath
####ファイル名
set ocidFileName to ocidNSUrlPath's lastPathComponent
####拡張子を除いたファイル名
set strPrefixName to (ocidFileName's stringByDeletingPathExtension) as text

##読み込み (テキスト)
set ocidReadM3Udata to objNSString's stringWithContentsOfFile:ocidFilePath
###改行でリスト化
set ocidReadM3UdataArray to ocidReadM3Udata's componentsSeparatedByString:"\n"
###ダウンロードするテンポラリーファイルのナンバリング
set strFileNo to 1000 as number
###改行だけ繰返し
repeat with objReadM3UdataArray in ocidReadM3UdataArray
###テキストにして
set strReadM3UdataArray to objReadM3UdataArray as text
####EXT-X-MAP 部を最初に処理 初期化セクション
if strReadM3UdataArray starts with "#EXT-X-MAP" then
###ファイル番号カウントアップ
set strFileNo to strFileNo + 1 as number
set strMapPath to doReplace(strReadM3UdataArray, "#EXT-X-MAP:URI=", "")
set strMapPath to doReplace(strMapPath, "\"", "")
###URL整形
set strURL to (strBaseURL & strMapPath) as text
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".m4s'" as text
do shell script strCommandText
else if strReadM3UdataArray starts with "#" then
log "コメント行"
else if strReadM3UdataArray is "" then
log "空行"
else
#####コンテンツ部のダウンロード
###ファイル番号カウントアップ
set strFileNo to strFileNo + 1 as number
####ドキュメントのパスをNSURL
set ocidNSUrlReadM3UdataArray to (objNSURL's fileURLWithPath:objReadM3UdataArray)
####ファイル名
set ocidM3UFileName to ocidNSUrlReadM3UdataArray's lastPathComponent
####拡張子
set strM3UPrefixName to (ocidM3UFileName's pathExtension) as text
log strM3UPrefixName
### URL整形
set strURL to (strBaseURL & strReadM3UdataArray) as text
if strM3UPrefixName is "m4s" then
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".m4s'" as text
else if strM3UPrefixName is "ts" then
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".ts'" as text
end if
###コマンド実行
do shell script strCommandText
end if

end repeat
#####
(*
要は元のMP4だったりTSファイルをsplitしてある『だけ』なので
CATで結合できます。

*)
if strM3UPrefixName is "m4s" then
###ダウンロード終わったものをまとめる
do shell script "/bin/cat " & strDirPath & "/*m4s >> ~/Desktop/" & strPrefixName & ".mp4"
else if strM3UPrefixName is "ts" then
###ダウンロード終わったものをまとめる
do shell script "/bin/cat " & strDirPath & "/*ts >> ~/Desktop/" & strPrefixName & ".ts"
end if





to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace


#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[m3u]Twitterビデオダウンロード(ヘルパー)TS用

Twitterビデオのm3uファイルから
TSファイルをダウンロードして1つのTSファイルに結合します。



#!/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 scripting additions


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL

set objFileManager to objMe's NSFileManager's defaultManager()


####BaseURL
set strBaseURL to "https://video.twimg.com"


###日付取得
###フォーマットは<http://nsdateformatter.com>参照
set strDateFormat to "yyyyMMddhhmmss" as text
set ocidForMatter to objMe's NSDateFormatter's alloc()'s init()
ocidForMatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidForMatter's setDateFormat:(strDateFormat)
set theString to (ocidForMatter's stringFromDate:(current date)) as text
####作成するダウンロードフォルダのパス
set strDirPath to ("/tmp/" & theString & "")
set objDirPath to objNSString's stringWithString:strDirPath
###フォルダを作る
set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:objDirPath withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))
###エラー判定
if boolMakeNewFolder is false then
return "ダウンロードフォルダの作成に失敗しました"
end if
(*
テンポラリーファイルを/tmpに作る事で
次回の再起動時に自動的に削除されるメリットがあります
*)
######ログ表示
doLogView()

####ダイアログで使うデフォルトロケーション
tell application "Finder"
##set aliasDefaultLocation to container of (path to me) as alias
set aliasDefaultLocation to (path to downloads folder from user domain) as alias
end tell

####UTIリスト m3uのみ
set listUTI to {"public.m3u-playlist"}

####ダイアログを出す
set aliasFilePath to (choose file with prompt "m3uファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

set strFilePath to POSIX path of aliasFilePath

####ドキュメントのパスをNSString
set ocidFilePath to objNSString's stringWithString:strFilePath
####ドキュメントのパスをNSURL
set ocidNSUrlPath to objNSURL's fileURLWithPath:ocidFilePath
####ファイル名
set ocidFileName to ocidNSUrlPath's lastPathComponent
####拡張子を除いたファイル名
set strPrefixName to (ocidFileName's stringByDeletingPathExtension) as text

##読み込み (テキスト)
set ocidReadM3Udata to objNSString's stringWithContentsOfFile:ocidFilePath
###改行でリスト化
set ocidReadM3UdataArray to ocidReadM3Udata's componentsSeparatedByString:"\n"
###ダウンロードするテンポラリーファイルのナンバリング
set strFileNo to 1000 as number
###改行だけ繰返し
repeat with objReadM3UdataArray in ocidReadM3UdataArray

###テキストにして
set strReadM3UdataArray to objReadM3UdataArray as text
if strReadM3UdataArray starts with "#" then
log "コメント行"
else
###ファイル番号カウントアップ
set strFileNo to strFileNo + 1 as number
###URL整形
set strURL to (strBaseURL & strReadM3UdataArray) as text
###コマンド整形
set strCommandText to "/usr/bin/curl -k '" & strURL & "' -o '" & strDirPath & "/" & strFileNo & ".ts'" as text
###コマンド実行
do shell script strCommandText
end if

end repeat
###ダウンロード終わったものをまとめる
do shell script "/bin/cat " & strDirPath & "/* >> ~/Desktop/" & strPrefixName & ".ts"




#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[Google Chrome]Twitterへ投稿する

1:URLを取得する
2:タイトルを取得する
3:%エンコードする
4:URLを整形して
5:URLを開く を処理します

ダウンロード - twittere381b8e68a95e7a8bf.zip


#!/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.4"
use framework "Foundation"
use scripting additions

tell application "AppleScript Utility"
set application scripts position to top
set Script menu enabled to true
set show Computer scripts to true
set boolGuiScript to GUI Scripting enabled
if boolGuiScript is false then
GUI Scripting enabled
end if
set theAppPath to default script editor
log theAppPath
end tell


tell application "Finder"
set aliasScriptPath to path to scripts folder from user domain
set boolFolderChk to exists of (folder "Applications" of folder aliasScriptPath)
if boolFolderChk is false then
make new folder at aliasScriptPath with properties {name:"Applications", displayed name:"Applications", comment:"Applications"}
end if
set aliaseScriptAppPath to (folder "Applications" of folder aliasScriptPath) as alias
set boolFolderChk to exists of (folder "Google Chrome" of folder aliaseScriptAppPath)
if boolFolderChk is false then
make new folder at aliaseScriptAppPath with properties {name:"Google Chrome", displayed name:"Google Chrome", comment:"Google Chrome"}
end if

set aliasDistDir to (folder "Google Chrome" of folder aliaseScriptAppPath) as alias
set theDistDir to POSIX path of aliasDistDir as text

end tell


tell application "Finder"
set aliasContainerDir to container of (path to me) as alias
set theContainerDir to POSIX path of aliasContainerDir as text
end tell

set theCommandText to ("ditto \"" & theContainerDir & "Google Chrome\" \"" & theDistDir & "\"")
do shell script theCommandText



tell application "Finder"



open (folder "Twitterへ投稿" of folder "Google Chrome" of folder aliaseScriptAppPath)
select (folder "Twitterへ投稿" of folder "Google Chrome" of folder aliaseScriptAppPath)
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom