Microsoft Excel

[Excel]URLをセルイメージ関数に(単機能)

202504090526121_1368x990

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

URLをセルイメージ関数に.Applescript
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004URLをセルイメージイメージ関数に
005エクセル用
006com.cocolog-nifty.quicktimer.icefloe *)
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "UniformTypeIdentifiers"
011use framework "AppKit"
012use scripting additions
013property refMe : a reference to current application
014
015
016set strMes to ("画像のURLhttpから入力してください") as text
017
018########################
019## クリップボードの中身取り出し
020########################
021###初期化
022set appPasteboard to refMe's NSPasteboard's generalPasteboard()
023##格納されているタイプをリストにして
024set ocidPastBoardTypeArray to appPasteboard's types()
025###テキストがあれば
026set boolContain to ocidPastBoardTypeArray's containsObject:(refMe's NSPasteboardTypeString)
027if (boolContain as boolean) is true then
028   set ocidTypeClassArray to refMe's NSMutableArray's alloc()'s init()
029   ocidTypeClassArray's addObject:(refMe's NSString)
030   set ocidReadStringArray to appPasteboard's readObjectsForClasses:(ocidTypeClassArray) options:(missing value)
031   set ocidReadString to ocidReadStringArray's firstObject()
032else
033   ###NSStringが無いなら public.utf8があるか?確認して
034   set boolContain to ocidPastBoardTypeArray's containsObject:("public.utf8-plain-text")
035   ##テキスト形式があるなら
036   if (boolContain as boolean) is true then
037      ###値を格納する
038      tell application "Finder"
039         set strReadString to (the clipboard as text) as text
040      end tell
041      set ocidReadString to refMe's NSString's stringWithString:(strReadString)
042   else
043      # "テキストなし"
044      set ocidReadString to refMe's NSString's stringWithString:("")
045   end if
046end if
047
048set strReadString to ocidReadString as text
049##############################
050#####ダイアログ
051##############################
052set boolCalculator to (missing value)
053###ダイアログを前面に出す
054set strName to (name of current application) as text
055if strName is "osascript" then
056   tell application "System Events" to activate
057else
058   tell current application to activate
059end if
060set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
061try
062   tell application "System Events"
063      activate
064      set recordResult to (display dialog strMes with title "画像のURLを入力してください" default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
065   end tell
066on error
067   tell application "System Events" to quit
068   log "エラーしました"
069   return
070end try
071if "OK" is equal to (button returned of recordResult) then
072   set strReturnedText to (text returned of recordResult) as text
073else if (gave up of recordResult) is true then
074   return "時間切れです"
075else
076   return "キャンセル"
077end if
078##############################
079#####戻り値整形
080##############################
081set ocidResponseText to (refMe's NSMutableString's stringWithString:(strReturnedText))
082
083###除去する文字列リスト
084set listRemoveChar to {"\n", "\r", "\t", "¥", ""} as list
085##置換
086repeat with itemChar in listRemoveChar
087   set strPattern to itemChar as text
088   set strTemplate to ("") as text
089   set ocidOption to (refMe's NSRegularExpressionCaseInsensitive)
090   set listResponse to (refMe's NSRegularExpression's regularExpressionWithPattern:(strPattern) options:(ocidOption) |error|:(reference))
091   if (item 2 of listResponse) ≠ (missing value) then
092      log (item 2 of listResponse)'s localizedDescription() as text
093      return "正規表現パターンに誤りがあります"
094   else
095      set ocidRegex to (item 1 of listResponse)
096   end if
097   set numLength to ocidResponseText's |length|()
098   set ocidRange to refMe's NSRange's NSMakeRange(0, numLength)
099   set ocidResponseText to (ocidRegex's stringByReplacingMatchesInString:(ocidResponseText) options:0 range:(ocidRange) withTemplate:(strTemplate))
100end repeat
101set boolURL to ocidResponseText's hasPrefix:("http")
102if boolURL is false then
103   return "URL以外は処理しません"
104else
105   set strTextM to ocidResponseText as text
106end if
107
108##############################
109#関数設定
110##############################
111set strFuncsion to ("=IMAGE(\"" & strTextM & "\",\"イメージ\",0)") as text
112
113##############################
114#####ダイアログ
115##############################
116tell current application
117   set strName to name as text
118end tell
119if strName is "osascript" then
120   tell application "System Events" to activate
121else
122   tell current application to activate
123end if
124try
125   tell application "System Events"
126      activate
127      set recordResult to (display dialog strMes with title "戻り値です" default answer strFuncsion buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
128   end tell
129on error
130   tell application "System Events" to quit
131   return "エラーしました"
132end try
133if (gave up of recordResult) is true then
134   return "時間切れです"
135end if
136##############################
137#####自分自身を再実行
138##############################
139if button returned of recordResult is "再実行" then
140   tell application "Finder"
141      set aliasPathToMe to (path to me) as alias
142   end tell
143   run script aliasPathToMe with parameters "再実行"
144   return
145end if
146##############################
147#####値のコピー
148##############################
149if button returned of recordResult is "クリップボードにコピー" then
150   try
151      set strText to text returned of recordResult as text
152      ####ペーストボード宣言
153      set appPasteboard to refMe's NSPasteboard's generalPasteboard()
154      set ocidText to (refMe's NSString's stringWithString:(strText))
155      appPasteboard's clearContents()
156      appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
157   on error
158      tell application "Finder"
159         set the clipboard to strText as text
160      end tell
161   end try
162end if
163#終了前に呼び出してあったsystemeventsは終了させる
164#この2つの処理は基本不要なんだけど
165#なぜか残ることがあるので明示的に終了させるようにした
166tell application "System Events" to quit
167#スクリプトメニューからの実行を終了させる
168tell application id "com.apple.automator.xpc.runner" to quit
169return 0
AppleScriptで生成しました

| | コメント (0)

com.microsoft.officeでのVBの使用停止設定


サンプルコード

サンプルソース(参考)
行番号ソース
001<key>VBAObjectModelIsTrusted</key>
002<false />
003<key>AllowVisualBasicToBindToSystem</key>
004<false />
005
006<key>DisableVisualBasicExternalDylibs</key>
007<true />
008<key>DisableVisualBasicMacScript</key>
009<true />
010<key>DisableVisualBasicToBindToPopen</key>
011<true />
012<key>VisualBasicEntirelyDisabled</key>
013<true />
014<key>SendAllTelemetryEnabled</key>
015<false />
016
017<key>PayloadDisplayName</key>
018<string>Microsoft Office</string>
019<key>PayloadType</key>
020<string>com.microsoft.office</string>
AppleScriptで生成しました

|

[Excel]祭日入りカレンダー生成

Screencapture-20230610-130744

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

####設定項目
set numFontSize to 14 as number
##set strFontName to "Osaka−等幅" as text
##set strFontName to "Arial Unicode MS" as text
set strFontName to "メイリオ" as text


########################
#####ここから処理
####日付情報の取得--> 今の『年』の数値を求める
set ocidDate to refMe's NSDate's |date|()
set ocidCalendar to refMe's NSCalendar's autoupdatingCurrentCalendar()
set ocidCalendarUnitYear to refMe's NSCalendarUnitYear
set ocidCalendarUnitMonth to refMe's NSCalendarUnitMonth
set ocidDateComponents to ocidCalendar's components:((ocidCalendarUnitYear) + (ocidCalendarUnitMonth)) fromDate:ocidDate
set numSetYear to (ocidDateComponents's |year|) as integer
set numSetMonth to (ocidDateComponents's |month|) as integer
#####各種リスト
set listWeekDay to {"日", "月", "火", "水", "木", "金", "土"} as list
set listYear to {(numSetYear - 1), (numSetYear), (numSetYear + 1)} as list
set listMonth to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} as list
########################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####年ダイアログを出す
try
  set objResponseYear to (choose from list listYear with title "年選択" with prompt "年を選択してください" default items (item 2 of listYear) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
  log "エラーしました"
return
end try
if objResponseYear is false then
return
end if
set numSetYear to (objResponseYear) as integer
########################
#####月ダイアログを出す
if numSetMonth = 12 then
  set numSetMonth to 1 as integer
else
  set numSetMonth to numSetMonth + 1 as integer
end if
try
  set objResponseMonth to (choose from list listMonth with title "月選択" with prompt "月を選択してください" default items (item (numSetMonth) of listMonth) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
  log "エラーしました"
return
end try
if objResponseMonth is false then
return
end if
set numSetMonth to (objResponseMonth) as integer



########################
tell application "Microsoft Excel" to launch
###エクセルの基本処理
set strMonthNoZeroSupp to (text -2 through -1 of ("00" & numSetMonth)) as text
set strSheetName to ("" & numSetYear & "-" & strMonthNoZeroSupp & "") as text
set strFileName to ("" & strSheetName & "カレンダーxlsx") as text
set strDesktopPath to POSIX path of (path to desktop folder from user domain) as text
set strSaveFilePath to (strDesktopPath & strFileName) as text
####新規ワークブック
tell application "Microsoft Excel"
  activate
  set objWorkBook to make new workbook with properties {excel 8 compatibility mode:false}
  tell objWorkBook
    set strWorkBookName to name as text
  end tell
end tell
####シートの名前の変更
tell application "Microsoft Excel"
  tell objWorkBook
    tell active sheet
      set name to strSheetName
    end tell
  end tell
end tell
###A1 左上のセルの処理
tell application "Microsoft Excel"
  tell objWorkBook
    tell sheet strSheetName
      tell cell "A1"
set number format to "@"
###Aに年月を入力
set value to ("" & (numSetYear as text) & "/" & strMonthNoZeroSupp) as text
####タイトル行の処理
tell cell "$1:$1"
tell font object
set font size to numFontSize
set name to strFontName
set color to {0, 0, 0}
end tell
tell interior object
set color to {255, 255, 255}
end tell
tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
end tell
      end tell
    end tell
  end tell
end tell
########################
#####カレンダー初期化
set ocidCalendar to refMe's NSCalendar's calendarWithIdentifier:(refMe's NSCalendarIdentifierGregorian)
set ocidLocale to refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP")
ocidCalendar's setLocale:(ocidLocale)
#####日付コンポーネント初期化
set ocidDateComponents to refMe's NSDateComponents's alloc()'s init()
ocidDateComponents's setYear:(numSetYear)
ocidDateComponents's setMonth:(numSetMonth)
set ocidDate to ocidCalendar's dateFromComponents:(ocidDateComponents)
###指定月のカレンダーの最大日数-->繰り返し回数になる
set ocidMonthDateRange to ocidCalendar's rangeOfUnit:(refMe's NSCalendarUnitDay) inUnit:(refMe's NSCalendarUnitMonth) forDate:(ocidDate)
set numDateLength to ocidMonthDateRange's |length|


########################
###祭日データJSONで取得
set strURL to "https://holidays-jp.github.io/api/v1/date.json" as text
set ocidJsonURL to refMe's NSURL's URLWithString:(strURL)
set ocidOption to refMe's NSDataReadingMappedIfSafe
set listDownLoadData to refMe's NSData's dataWithContentsOfURL:(ocidJsonURL) options:(ocidOption) |error|:(reference)
set ocidJsonData to (item 1 of listDownLoadData)
#####################
###JSON初期化 してレコードに格納
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:0 |error|:(reference))
set ocidJsonData to item 1 of listJSONSerialization
set ocidHolidayDict to refMe's NSDictionary's alloc()'s initWithDictionary:(ocidJsonData)

#####################
###取得するカレンダーの月(処理としては不要なんだけど、今後の展開のために処理)
set numYear to ocidCalendar's component:(refMe's NSCalendarUnitYear) fromDate:(ocidDate)
set numMonth to ocidCalendar's component:(refMe's NSCalendarUnitMonth) fromDate:(ocidDate)
###年はそのまま
set strYear to numYear as text
###月はゼロパディング
set strMonth to (text -2 through -1 of ("00" & (numMonth as text))) as text
###日付毎処理
set numCntRows to 2

repeat with numDayNo from (1) to (numDateLength)
  -->ここまでは年と月でのカレンダーなので
  ###日付を入れて
(ocidDateComponents's setDay:(numDayNo))
  set ocidDate to (ocidCalendar's dateFromComponents:(ocidDateComponents))
  set ocidWeekDayClender to (ocidCalendar's components:(refMe's NSWeekdayCalendarUnit) fromDate:(ocidDate))
  ###日付
  log ocidDate as date
  ###日付番号
  log numDayNo
  set strDayNoZeroSupp to (text -2 through -1 of ("00" & numDayNo)) as text
  #####################
  ###曜日処理
  set numWeekDayNo to (ocidWeekDayClender's |weekday|)'s intValue()
  ###曜日番号
  log numWeekDayNo
  ###曜日テキスト
  set strWeekDayJp to (item numWeekDayNo of listWeekDay) as text
  ###祭日取得用
  set strDateText to ("" & strYear & "-" & strMonth & "-" & strDayNoZeroSupp & "") as text
  ###祭日取得
  set ocidHolidayValue to (ocidHolidayDict's valueForKey:(strDateText))
  ###祭日処理
  if ocidHolidayValue is (missing value) then
    set numChkHoliday to 0 as integer
  else
    set numChkHoliday to 1 as integer
    set strHolidayValue to ocidHolidayValue as text
    log strHolidayValue
    ####Cの列
    set strCellNoHoliday to ("C" & numCntRows & "") as text
    tell application "Microsoft Excel"
      tell objWorkBook
tell sheet strSheetName
tell cell strCellNoHoliday
###Cの列に祭日名を入力
set value to (strHolidayValue)
end tell
end tell
      end tell
    end tell
  end if
  
  ###セル番号
  set strCellNoDay to ("A" & numCntRows & "") as text
  set strCellNoWeek to ("B" & numCntRows & "") as text
  set strCellRowsRange to "$" & numCntRows & ":$" & numCntRows & ""
  
  ########################
  ###エクセル処理
  tell application "Microsoft Excel"
    tell objWorkBook
      tell sheet strSheetName
tell cell strCellNoWeek
set value to strWeekDayJp
end tell
tell cell strCellNoDay
set value to strDayNoZeroSupp
end tell
      end tell
    end tell
    #######行処理
    tell cell strCellRowsRange
      set number format to "@"
      #####
      tell interior object
if numWeekDayNo = 1 then
set color to {254, 188, 190}
else if numWeekDayNo = 7 then
set color to {212, 243, 255}
else if numChkHoliday = 1 then
set color to {254, 188, 190}
else
set color to {255, 255, 255}
end if
      end tell
      #####
      tell font object
set font size to numFontSize
set name to strFontName
if numWeekDayNo = 1 then
set color to {170, 0, 0}
else if numWeekDayNo = 7 then
set color to {0, 88, 176}
else if numChkHoliday = 1 then
set color to {170, 0, 0}
else
set color to {0, 0, 0}
end if
      end tell
      tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
    end tell
  end tell
  
  set numCntRows to numCntRows + 1
end repeat

|

[Excel]行番号を入れる(パディング)

Screencapture-20230519-131838

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set strZeroSup to "000" as text

set numMaxRow to 200 as integer

###起動
tell application "Microsoft Excel"
  launch
end tell
####起動待ち最大20秒
repeat 20 times
  tell application "Microsoft Excel"
    activate
    set boolFrontMost to frontmost as boolean
  end tell
  if boolFrontMost is true then
    exit repeat
  end if
  delay 1
end repeat

####ワークブック開いているか?チェック
tell application "Microsoft Excel"
  set refAcvWorkBook to active workbook
  if refAcvWorkBook is (missing value) then
return "ワークブックを開いていません"
  end if
end tell
##################################
###本処理
##################################
set numLineNo to 1 as integer
repeat (numMaxRow + 1) times
  if numLineNo = 1 then
    ####シートの名前の変更
    tell application "Microsoft Excel"
tell active workbook
tell active sheet
tell cell "A1"
###A1に斜線を入れる
tell border id diagonal down
set color to {0, 0, 0}
set line style to continuous
set weight to border weight thin
end tell
end tell
end tell
end tell
    end tell
  else
    ###項番ゼロパディング
    set strCellValue to (text -3 through -1 of (strZeroSup & (numLineNo - 1)) as text) as text
    ###セル番号整形
    set strCellNo to ("A" & (numLineNo as text)) as text
    tell application "Microsoft Excel"
tell active workbook
tell active sheet
tell cell strCellNo
##表示形式をテキストにして
set number format local to "@"
set number format to "@"
##あたいを入れる
set value to strCellValue
end tell
end tell
end tell
    end tell
  end if
  set numLineNo to numLineNo + 1 as integer
end repeat




|

[Excel]シートの使用中エリア全部でHTMLファイルにする

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

#!/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 refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidPublicHTML to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeHTML)
if ocidPublicHTML is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "html"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
ocidPublicHTML's writeToURL:(ocidFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]シートの使用中エリア全部でPNGファイルにする

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

#!/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 refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell

if rangeArea is (missing value) then
return "取得に失敗しました"
end if

tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "png"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]シートの使用中エリア全部でPDFファイルにする

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

#!/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 refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePDF)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "pdf"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲のRangeの取得

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

tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
#####ログは以下のようになります
tell application "Microsoft Excel"
  get address local selection
    --> "$A$1:$F$12"
  get areas of cell "$A$1:$F$12" of active sheet
    --> {range "[Book1]Sheet1!$A$1:$F$12"}
end tell
結果:
{range "[Book1]Sheet1!$A$1:$F$12" of application "Microsoft Excel"}

|

[Excel]選択範囲でPNGファイルにする

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

#!/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 refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell

if rangeArea is (missing value) then
return "取得に失敗しました"
end if

tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "png"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲でPDFファイルにする

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

#!/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 refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePDF)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "pdf"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings 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 VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom