AppleScript Jedit

[Jedit Ω]HTMLのタグ内の改行を戻す(正規表現)

Screen-6

([^>])$\n

\1△

|

[Jedit Ω] 日付挿入


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#カーソル位置に元号(令和)日付をスタンプします
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to ("jp.co.artman21.JeditOmega") as text


###今日
set ocidDate to (refMe's NSDate's |date|())
###フォーマット初期化
set ocidFormatterJP to refMe's NSDateFormatter's alloc()'s init()
###日本のカレンダー
set ocidCalendarJP to refMe's NSCalendar's alloc()'s initWithCalendarIdentifier:(refMe's NSCalendarIdentifierJapanese)
###東京タイムゾーン
set ocidTimezoneJP to refMe's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
###日本語
set ocidLocaleJP to refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
###フォーマットをセット
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
ocidFormatterJP's setDateStyle:(refMe's NSDateFormatterFullStyle)
ocidFormatterJP's setDateFormat:("GGyy")
###今日の日付にフォーマットを適応
set ocidDateStringEra to ocidFormatterJP's stringFromDate:(ocidDate)
ocidFormatterJP's setDateFormat:("年MM月dd日EEEE")
set ocidDateString to ocidFormatterJP's stringFromDate:(ocidDate)
set strDateText to ((ocidDateStringEra as text) & (ocidDateString as text)) as text
########################################
### エラー制御
########################################

tell application id strBundleID
  set numCntOpenDoc to (count document) as integer
end tell
if numCntOpenDoc = 0 then
  set aliasIconPath to doGetIconPath(strBundleID)
  ###ダイアログ
  #####ダイアログを前面に
  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
  set strMes to "ドキュメントを開いていません"
  set strTitle to "エラー"
  display dialog strMes with title strTitle buttons {"OK"} default button "OK" giving up after 1 with icon aliasIconPath without hidden answer
return strMes
end if
###選択中のテキスト格納
tell front document of application "Jedit Ω"
  activate
  set strSelectedText to selected text
end tell
###選択中のテキストに日付を加えて戻す
tell front document of application "Jedit Ω"
  activate
  set selected text to (strSelectedText & strDateText)
end tell
return ((ocidDateStringEra as text) & (ocidDateString as text)) as text




########################################
### アイコンパス
########################################
to doGetIconPath(argBundleID)
  ##初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのインストール先を求める
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id argBundleID) as alias
set strAppPath to POSIX path of aliasAppApth as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
  ###アイコン名をPLISTから取得
  set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
  ###ICONのURLにして
  set strPath to ("Contents/Resources/" & strIconFileName) as text
  set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
  ###拡張子の有無チェック
  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
  if strExtensionName is "" then
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
  end if
  ###ICONファイルが実際にあるか?チェック
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
  ###ICONがみつかない時用にデフォルトを用意する
  if boolExists is false then
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
  else
    set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  end if
return aliasIconPath as alias
end doGetIconPath

|

[Jedit Ω]ターミナルで開く


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#カーソル位置に元号(令和)日付をスタンプします
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to ("jp.co.artman21.JeditOmega") as text

########################################
### エラー制御
########################################
tell application id strBundleID
  set numCntOpenDoc to (count document) as integer
end tell
if numCntOpenDoc = 0 then
  set aliasIconPath to doGetIconPath(strBundleID)
  #####ダイアログを前面に
  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
  set strMes to "ドキュメントを開いていません"
  set strTitle to "エラー"
  set recordResult to (display dialog strMes with title strTitle buttons {"OK"} default button "OK" giving up after 1 with icon aliasIconPath without hidden answer)
return "ドキュメントがありません"
end if
########################################
### エラー制御
########################################
tell application "Jedit Ω"
  tell front document
    properties
    set strFileName to name as text
    set strFilePath to path as text
  end tell
end tell

if strFileName does not end with "sh" then
  set aliasIconPath to doGetIconPath(strBundleID)
  #####ダイアログを前面に
  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
  set strMes to "スクリプトファイルではありません"
  set strTitle to "エラー"
  display dialog strMes with title strTitle buttons {"OK"} default button "OK" giving up after 1 with icon aliasIconPath without hidden answer
return strMes
end if
###実行可能にしておく
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidFilePath) |error|:(reference)
########################################
### ターミナルで実行
########################################
## 実行中チェック
tell application "Terminal"
  set numCntWindow to (count of every window) as integer
end tell
if numCntWindow = 0 then
  log "Windowないので新規で作る"
  tell application "Terminal"
    set objNewWindow to (do script "\n")
  end tell
else
  log "Windowがある場合は、何か実行中か?をチェック"
  tell application "Terminal"
    tell front window
      tell front tab
set boolTabStatus to busy as boolean
set listProcess to processes as list
      end tell
    end tell
    set objNewWindow to selected tab of front window
  end tell
  ###前面のタブがbusy=実行中なら新規Window作る
  if boolTabStatus = true then
    tell application "Terminal"
      set objNewWindow to (do script "\n")
    end tell
  else if listProcess = {} then
    tell application "Terminal"
      set objNewWindow to (do script "\n")
    end tell
  end if
end if
##############################
## コマンド実行
set strCommandText to ("\"" & strFilePath & "\"") as text
tell application "Terminal"
  activate
do script strCommandText in objNewWindow
end tell


########################################
### アイコンパス
########################################
to doGetIconPath(argBundleID)
  ##初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのインストール先を求める
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
set aliasAppApth to (application file id argBundleID) as alias
set strAppPath to POSIX path of aliasAppApth as text
set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set strAppPath to strAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
  ###アイコン名をPLISTから取得
  set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
  ###ICONのURLにして
  set strPath to ("Contents/Resources/" & strIconFileName) as text
  set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
  ###拡張子の有無チェック
  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
  if strExtensionName is "" then
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
  end if
  ###ICONファイルが実際にあるか?チェック
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
  ###ICONがみつかない時用にデフォルトを用意する
  if boolExists is false then
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
  else
    set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  end if
return aliasIconPath as alias
end doGetIconPath

|

[Jedit Ω]正規表現でNULL文字除去


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

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




tell application "Jedit Ω"
  set strSerchText to "\\x{00}"
  tell front document
replaceAll string "\\x{00}" to "" with grep, select all, case sensitive, character width sensitive and diacritic sensitive
  end tell
end tell

AppleScriptでやるとおおげさな感じになるなぁ

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

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


tell application "Jedit Ω"
  tell front document
    set strEveryText to every text
  end tell
end tell


set ocidEveryText to refMe's NSString's stringWithString:(strEveryText)
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidEveryText)


#################################################
## 正規表現でNULL文字削除
#################################################

set ocidRegOption to (refMe's NSRegularExpressionUseUnicodeWordBoundaries)
(*
-->(*1*)アルファベットの大文字と小文字の区別無し
(refMe's NSRegularExpressionCaseInsensitive)
-->(*2*)スペースと#コメントを無視
(refMe's NSRegularExpressionAllowCommentsAndWhitespace)
-->(*4*)メタ文字無視
(refMe's NSRegularExpressionIgnoreMetacharacters)
-->(*8*)ドット=.が改行コードにもマッチ
(refMe's NSRegularExpressionDotMatchesLineSeparators)
-->(*16*)行頭行末の^$が各行マッチ
(refMe's NSRegularExpressionAnchorsMatchLines)
-->(*32*)\nだけが改行コード 他の改行コードはマッチの対象
(refMe's NSRegularExpressionUseUnixLineSeparators)
-->(*64*)ユニコード式の文字区切り \b
(refMe's NSRegularExpressionUseUnicodeWordBoundaries)
*)
set listRegularExpression to refMe's NSRegularExpression's regularExpressionWithPattern:("\\x00") options:(ocidRegOption) |error|:(reference)
set ocidRegex to (item 1 of listRegularExpression)
set ocidLength to ocidTextM's |length|()
set ocidTextRange to refMe's NSMakeRange(0, ocidLength)
set ocidMachOption to (refMe's NSMatchingReportProgress)
(*
-->(*1*) ブロックを定期的に呼び出
(refMe's NSMatchingReportProgress)
-->(*2*)マッチングが完了したら、ブロックを 1 回呼び出し
(refMe's NSMatchingReportCompletion)
-->(*4*)一致を検索範囲の先頭の一致に限定
(refMe's NSMatchingAnchored)
-->(*8*)検索範囲の境界を越える文字列の一部を照合
(refMe's NSMatchingWithTransparentBounds)
-->(*16*)文字列全体の先頭と末尾には一致
(refMe's NSMatchingWithoutAnchoringBounds)
*)
set ocidResults to ocidRegex's stringByReplacingMatchesInString:(ocidTextM) options:(ocidMachOption) range:(ocidTextRange) withTemplate:("")
set strTrimText to ocidResults as text

tell application "Jedit Ω"
  tell front document
    set every text to strTrimText
  end tell
end tell

|

[Jedit]列ペースト


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

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

########################
########設定項目
###新規? trueで新規 falseで前面書類に
set boolNewDoc to false as boolean

###本文行と挿入行を区切る文字を指定
set strLineNoSeparator to "\t" as text
(* 例 ↑はタブ区切りになります
set strLineNoSeparator to ":" as text
set strLineNoSeparator to "," as text
*)
################################
######ペーストボードテキスト取得
##初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
##可変テキストとして受け取る
set ocidPasteboardArray to ocidPasteboard's readObjectsForClasses:({refMe's NSMutableString}) options:(missing value)
if (count of ocidPasteboardArray) = 0 then
  ###初期値
return "挿入テキストをコピーしなおしてください"
else
  ###ペーストボードの中身をテキストで確定
  set strPasteboardStrings to (ocidPasteboardArray's objectAtIndex:0) as text
end if
###String
set ocidInsText to refMe's NSString's stringWithString:(strPasteboardStrings)
###改行コードで区切り
set ocidChrSet to refMe's NSCharacterSet's newlineCharacterSet()
####入力テキスト用のリスト
set ocidInsTextArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidInsTextArray to ocidInsText's componentsSeparatedByCharactersInSet:(ocidChrSet)

########################
########テキスト取得
####前面ドキュメントのテキストを取得
tell application "Jedit Ω"
  tell front document
    properties
    set strText to selected text
  end tell
end tell
if strText is "" then
return "本文を選択してください"
end if
###String
set ocidOrgText to refMe's NSString's stringWithString:(strText)
###改行コードで区切り
set ocidChrSet to refMe's NSCharacterSet's newlineCharacterSet()
####入力テキスト用のリスト
set ocidOrgTextArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidOrgTextArray to ocidOrgText's componentsSeparatedByCharactersInSet:(ocidChrSet)
###出力用のArray
set ocidOutPutTextArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
########################
##本処理
########################
set numCntOrgLineNo to 0 as integer
####行データ分繰り返し
repeat with itemOrgTextArray in ocidOrgTextArray
  set strAddLineText to "" as text
  set strAddLineText to itemOrgTextArray as text
  set strAddLineText to (strAddLineText & strLineNoSeparator) as text
  ###挿入側を取り出し
  set ocidInsString to (ocidInsTextArray's objectAtIndex:(numCntOrgLineNo))
  set strInsString to ocidInsString as text
  set strAddLineText to (strAddLineText & strInsString) as text
(ocidOutPutTextArray's addObject:(strAddLineText))
  set numCntOrgLineNo to numCntOrgLineNo + 1 as integer
end repeat
########################
##出力
########################
####出力用のリストを項目毎に改行入れてテキストに
set ocidOutPutText to ocidOutPutTextArray's componentsJoinedByString:"\n"
####出力用のテキストで確定
set strOutPutText to ocidOutPutText as text
########################
####新規ドキュメントを作ってテキストを戻す
tell application "Jedit Ω"
  if boolNewDoc is true then
make new document with properties {encoding:"Unicode (UTF-8)", line endings:LF}
  end if
  tell front document
    set selected text to strOutPutText
  end tell
end tell



|

[Jedit Ω]前面書類がシェルスクリプトならターミナルで開く


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

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

##対応拡張子リスト
set listExtension to {"sh", "bash", "command"}


###前面ドキュメントのパスを取得
tell application "Jedit Ω"
  tell front document
    set strFilePath to path as text
  end tell
end tell

if strFilePath is "" then
return "未保存です"
else
  ###拡張子取得
  tell application "Finder"
    set aliasFilePath to (POSIX file strFilePath) as alias
    set recordFileInfo to info for aliasFilePath
    set strNameExtension to (name extension of recordFileInfo) as text
  end tell
end if
if listExtension does not contain strNameExtension then
return "シェルスクリプト専用です"
end if
###アクセス権設定
(* 普通はこっちだね
set strCommandText to ("/bin/chmod 755 \"" & strFilePath & "\"") as text
do shell script strCommandText
*)
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
644-->420
600-->384
*)
##パス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
##アトリビュート アクセス権755
set ocidAttrArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidAttDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set ocidLogValue to refMe's NSNumber's numberWithUnsignedLong:(493)
ocidAttDict's setValue:(ocidLogValue) forKey:(refMe's NSFilePosixPermissions)
##アクセス権を設定
set appFileManager to refMe's NSFileManager's defaultManager()
appFileManager's setAttributes:(ocidAttDict) ofItemAtPath:(ocidFilePath) |error|:(reference)

###ターミナルで実行する
tell application "Terminal"
  launch
  activate
  set objWindowID to (do script "\n\n")
  delay 0.5
do script strFilePath in objWindowID
end tell


sudoの場合用

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

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

##対応拡張子リスト
set listExtension to {"sh", "bash", "command"}


###前面ドキュメントのパスを取得
tell application "Jedit Ω"
  tell front document
    set strFilePath to path as text
  end tell
end tell

if strFilePath is "" then
return "未保存です"
else
  ###拡張子取得
  tell application "Finder"
    set aliasFilePath to (POSIX file strFilePath) as alias
    set recordFileInfo to info for aliasFilePath
    set strNameExtension to (name extension of recordFileInfo) as text
  end tell
end if
if listExtension does not contain strNameExtension then
return "シェルスクリプト専用です"
end if
###アクセス権設定
(* 普通はこっちだね
set strCommandText to ("/bin/chmod 755 \"" & strFilePath & "\"") as text
do shell script strCommandText
*)
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
644-->420
600-->384
*)
##パス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
##アトリビュート アクセス権755
set ocidAttrArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidAttDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set ocidLogValue to refMe's NSNumber's numberWithUnsignedLong:(493)
ocidAttDict's setValue:(ocidLogValue) forKey:(refMe's NSFilePosixPermissions)
##アクセス権を設定
set appFileManager to refMe's NSFileManager's defaultManager()
appFileManager's setAttributes:(ocidAttDict) ofItemAtPath:(ocidFilePath) |error|:(reference)


set strCommandText to ("/usr/bin/sudo \"" & strFilePath & "\"") as text

###ターミナルで実行する
tell application "Terminal"
  launch
  activate
  set objWindowID to (do script "\n\n")
  delay 0.5
do script strCommandText in objWindowID
end tell


|

[Jedit Ω]前面書類がHTMLならブラウザで開く


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

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

property refMe : a reference to current application

tell application "Jedit Ω"
  tell front document
    set strFilePath to path as text
  end tell
end tell

if strFilePath is "" then
return "未保存です"
end if
###書類のURL
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 strFileExtension to ocidFilePathURL's pathExtension() as text

if strFileExtension is not "html" then
return "HTML書類用です"
end if


###設定項目ドキュメントのURL
set strScheme to "https://" as text
###NSURL
set ocidScheme to refMe's NSURL's URLWithString:(strScheme)
###ワークスペース初期化
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
###URLタイプのデフォルトアプリケーション
set ocidAppPathURL to appShardWorkspace's URLsForApplicationsToOpenURL:(ocidScheme)

###ダイアログ用のアプリケーション名リスト
set listAppName to {} as list
###アプリケーションのURLを参照させるためのレコード
set ocidBrowserDictionary to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
####################################################
####httpがスキームとして利用可能なアプリケーション一覧を取得する
####################################################
repeat with itemAppPathURL in ocidAppPathURL
  ###アプリケーションの名前
  set listResponse to (itemAppPathURL's getResourceValue:(reference) forKey:(refMe's NSURLNameKey) |error|:(missing value))
  set strAppName to (item 2 of listResponse) as text
  log "ブラウザの名前は:" & strAppName & "です"
  copy strAppName to end of listAppName
  ####パス
  set aliasAppPath to itemAppPathURL's absoluteURL() as alias
  log "ブラウザのパスは:" & aliasAppPath & "です"
  ####バンドルID取得
  set ocidAppBunndle to (refMe's NSBundle's bundleWithURL:(itemAppPathURL))
  set ocidBunndleID to ocidAppBunndle's bundleIdentifier
  set strBundleID to ocidBunndleID as text
  log "ブラウザのBunndleIDは:" & strBundleID & "です"
(ocidBrowserDictionary's setObject:(itemAppPathURL) forKey:(strAppName))
end repeat

################################
##ダイアログ
################################
###ダイアログを前面に出す
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 listResponse to (choose from list listAppName with title "選んでください" with prompt "URLを開くアプリケーションを選んでください" default items (item 1 of listAppName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed)
on error
  log "エラーしました"
return "エラーしました"
end try
if listResponse is false then
return "キャンセルしました"
end if
set strResponse to (item 1 of listResponse) as text
################################
##アプリケーションのURLを取得する
################################
###アプリケーションのURLを取り出す
set ocidAppPathURL to ocidBrowserDictionary's objectForKey:(strResponse)
###OPENするファイルのURLリスト
set ocidOpenURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidOpenURLArray's addObject:(ocidFilePathURL)
###OPEN config
set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidConfig's setHides:(false as boolean)
ocidConfig's setActivates:(true as boolean)
ocidConfig's setRequiresUniversalLinks:(false as boolean)
###指定のブラウザで開く
set boolResponse to appShardWorkspace's openURLs:(ocidOpenURLArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidConfig) completionHandler:(missing value)





|

[Jedit Ω]%エンコード(置換レコードに$を追加)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#Jedit用のURLエンコード
# 選択テキストを変換
#
#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 "Jedit Ω"
  tell front document
    set TheTextToEncode to selected text as text
  end tell
end tell
set TheTextToEncode to urlEncode(TheTextToEncode) as text
tell application "Jedit Ω"
  tell front document
    set selected text to TheTextToEncode
  end tell
end tell


on urlEncode(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 urlEncode

|

[Jedit Ω]タブ区切りテキストを置換でテーブルHTMLに

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

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


################################
#### 選択範囲のテキストを取得
################################
tell application "Jedit Ω"
  tell front document
    set strText to selected text as text
    set strLineEnd to (line endings) as text
  end tell
end tell
################################
#### エラー処理
################################
if strText is "" then
  log "選択されていません"
return "選択されていません"
end if
################################
#### 改行文字
################################
if strLineEnd is "LF" then
  set strLineEnd to "\n" as text
else if strLineEnd is "CR" then
  set strLineEnd to "\r" as text
else if strLineEnd is "CRLF" then
  set strLineEnd to "\r\n" as text
end if
################################
#### 改行文字でリスト化
################################
set AppleScript's text item delimiters to strLineEnd
set listAllTextLine to every text item of strText
set AppleScript's text item delimiters to ""

############################
######最大列数
############################
set numMaxColumnLine to 0 as integer
repeat with itemAllTextLine in listAllTextLine
  set AppleScript's text item delimiters to "\t"
  set listTabLine to every text item of itemAllTextLine
  set AppleScript's text item delimiters to ""
  set numCntTab to (count of listTabLine) as integer
  if numMaxColumnLine < numCntTab then
    set numMaxColumnLine to numCntTab as integer
  end if
end repeat

################################
#### 1行目を項目名として格納(thead)
################################
set strFirstLine to (item 1 of listAllTextLine) as text
##タブでリスト化
set AppleScript's text item delimiters to "\t"
set listColName to every text item of strFirstLine
set AppleScript's text item delimiters to ""
set strThead to "<thead><tr>" as text
set numCntNo to 1 as integer
repeat with itemTabText in listColName
  if numCntNo = 1 then
    set strTabHTML to "<th class=\"tabletitle\" title=\"列" & (numCntNo as text) & ":" & itemTabText & "\">" & itemTabText & "</th>" as text
  else
    set strTabHTML to "<th class=\"tabletitle\" title=\"列" & (numCntNo as text) & ":" & itemTabText & "\" scope=\"col\">" & itemTabText & "</th>" as text
  end if
  set strThead to strThead & strTabHTML as text
  set numCntNo to numCntNo + 1 as integer
end repeat
set strThead to strThead & "</thead></tr>\n<tbody title=\" \">" as text
################################
#### 1行目を削除した残りのリスト
################################
set nunCntList to (count of listAllTextLine) as integer
set listContentsLine to (items 2 thru nunCntList of listAllTextLine) as list
################################
#### 1行毎の処理
################################
set numCntLineNo to 1 as integer
set strContentsHTML to "" as text
repeat with itemLineText in listContentsLine
  if (itemLineText as text) is "" then
    exit repeat
  end if
  ################################
  ###タブ区切り処理
  ################################
  set AppleScript's text item delimiters to "\t"
  set listLineText to every text item of (itemLineText as text)
  set AppleScript's text item delimiters to ""
  set strLineHTML to "<tr>" as text
  set numTabNo to 1 as integer
  repeat with itemLineText in listLineText
    if (itemLineText as text) is "" then
set itemLineText to "&nbsp;"
    end if
    if numTabNo = 1 then
set strLineHTML to strLineHTML & "<th class=\"firstcolumn\" title=\"" & numCntLineNo & "行目" & numTabNo & "列目:" & (item numTabNo of listColName) & "\" scope=\"row\">" & itemLineText & "</th>" as text
    else
set strLineHTML to strLineHTML & "<td class=\"firstcolumn\" title=\"" & numCntLineNo & "行目" & numTabNo & "列目:" & (item numTabNo of listColName) & "\">" & itemLineText & "</td>" as text
    end if
    set numTabNo to numTabNo + 1 as integer
  end repeat
  set numCntLineNo to numCntLineNo + 1 as integer
  set strLineHTML to strLineHTML & "</tr>" as text
  set strContentsHTML to strContentsHTML & strLineHTML & "</tbody>" as text
end repeat


################################
###主要パーツ
################################
set strCssText to "<style>div.bordertable table{ border-collapse: collapse;table-layout: fixed;}div.bordertable td,div.bordertable th{border: solid 1px;padding: 3px;overflow: inherit;word-wrap: break-word; overflow-wrap: break-word;}th.tabletitle ,th.firstcolumn{font-weight: bold;}</style>"

set strTableHTML to "<div class=\"bordertable\"><table><caption>キャプションテキスト</caption>" as text

set strFooterHTML to "</tbody>\n<tfoot><tr><th colspan=\"" & numMaxColumnLine & "\">フッターテキスト</th></tr></tfoot>\n</table>\n</div>"

####出力用整形
set strOutPutHTML to "" & strCssText & strTableHTML & strThead & strContentsHTML & strFooterHTML & ""
################################
###出力
################################
####戻さずに新規
tell application "Jedit Ω"
  make new document with properties {text:strOutPutHTML}
end tell

(* 置き換える場合
tell application "Jedit Ω"
tell front document
set selected text to strOutPutHTML
end tell
end tell

*)

用紙サイズpt換算
用紙名widthheightpoint widthpoint height
A084111892383.93700793370.3937008
A15948411683.77952762383.9370079
A24205941190.55118111683.7795276
A3297420841.88976381190.5511811
A4210297595.2755906841.8897638
A5148210419.5275591595.2755906
A6105148297.6377953419.5275591
A774105209.7637795297.6377953
A85274147.4015748209.7637795
A93752104.8818898147.4015748
A10263773.7007874104.8818898
A11182651.023622073.7007874
A12131836.850393751.0236220
     
B0103014562919.68503944127.2440945
B172810302063.62204722919.6850394
B25157281459.84251972063.6220472
B33645151031.81102361459.8425197
B4257364728.50393701031.8110236
B5182257515.9055118728.5039370
B6128182362.8346457515.9055118
B791128257.9527559362.8346457
B86491181.4173228257.9527559
B94564127.5590551181.4173228
B10324590.7086614127.5590551
B11223262.362204790.7086614
B12162245.354330762.3622047
フッターテキスト

|

[Jedit Ω]タブ区切りテキストを置換でテーブルHTMLに(ボツ…失敗作)

これはダメ、複数一括置換を利用した方がいい

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

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

################################
#### 選択範囲のテキストを取得
################################
tell application "Jedit Ω"
  tell front document
    set strText to selected text as text
  end tell
end tell
################################
#### エラー処理
################################
if strText is "" then
  log "選択されていません"
return "選択されていません"
end if

################################
#### 処理
################################
tell application "Jedit Ω"
  tell front document
replaceAll string "\n" to "</td></tr>\n" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "\t" to "</td><td>" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "^(.*)</td" to "<tr><td>\\1</td" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "\n" to "" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "$" to "</td></tr>\n" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "</tr><tr>" to "</tr>\n<tr>\n" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "</td>" to "</td>\t" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "<tr><td>(.*?)</td>\t" to "<tr><td title=\"\\1\">\\1</td>\t" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "<td>(.*?)</td>" to "<td title=\"\\1\">\\1</td>" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "\t|\n" to "" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "$" to "</tbody></table></div>" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "^" to "<div class=\"bordertable\"><table><caption> </caption><thead title=\" \">" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "</caption>" to "</caption>\n" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "</tr><tr>" to "</tr>\n<tr>" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "^(<thead.*)\n" to "\\1</thead><tbody title=\" \">\n" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "\t" to "" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
replaceAll string "<div class=\"bordertable\">" to "<style>div.bordertable{border-collapse: collapse;table-layout: fixed;border-collapse: collapse;overflow: inherit;word-wrap: break-word;border-spacing: 0;}div.bordertable th,div.bordertable td{border: solid 1px;padding: 3px;}</style>\n<div class=\"bordertable\">" with grep without select all, case sensitive, character width sensitive and diacritic sensitive
    
  end tell
end tell

|

その他のカテゴリー

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