AppleScript StandardAdditions

[display dialog] 入力欄にドラッグ&ドロップでパスを取得する



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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


########################
## クリップボードの中身取り出し
########################
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
log "テキストなし"
    set strReadString to "" as text
  end if
end if
if strReadString starts with "/" then
  set strReadString to strReadString as text
else
  set strReadString to "" as text
end if
##############################
#####ダイアログ
##############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set strMes to "パス入力してください"
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title strMes default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
on error
log "エラーしました"
return
end try
if "OK" is equal to (button returned of recordResult) then
  set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else
return "キャンセル"
end if
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")



set ocidFilePathStr to (refMe's NSString's stringWithString:(ocidTextM))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true)
####UTIの取得
set ocidBunndle to refMe's NSBundle's bundleWithURL:(ocidFilePathURL)
set ocidBunndleID to ocidBunndle's bundleIdentifier()
set strBunndleID to (ocidBunndleID) as text
###missing value対策
if strBunndleID is "" then
  tell application "Finder"
    set objInfo to info for aliasFilePath
    set strBunndleID to bundle identifier of objInfo as text
  end tell
end if

####ダイアログに指定アプリのアイコンを表示する
set strIconPath to ""
###アイコン名をPLISTから取得
set ocidPlistPathURL to ocidFilePathURL'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 ocidFilePathURL'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
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###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
  set strIconPath to ocidIconFilePathURL's |path|() as text
end if
if strIconPath is (missing value) then
  set strIconPath to ""
end if

set strMes to ("bundle identifier 戻り値です\rIconPath\r" & strIconPath) as text

set recordResult to (display dialog strMes with title "bundle identifier" default answer strBunndleID buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "クリップボードにコピー" then
  try
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strTitle as text
    end tell
  end try
end if



|

スクリプトの設定にPLISTを使う(考え中)


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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

####設定
property strMes : ("Xid(twitterID)を入力してください ") as text

###任意項目
property strBundleID : ("com.microsoft.edgemac") as text
set strKeyName to ("twitter.com") as text
####設定ファイル
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationSupportDirPathURL to ocidURLsArray's firstObject()
set ocidPreferencesDirPathURL to ocidApplicationSupportDirPathURL's URLByAppendingPathComponent:("com.cocolog-nifty.quicktimer")
#フォルダ作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidPreferencesDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#設定ファイルパス
set ocidPreferencesFileBasePathURL to ocidPreferencesDirPathURL's URLByAppendingPathComponent:(strBundleID)
set ocidPlistFilePathURL to ocidPreferencesFileBasePathURL's URLByAppendingPathExtension:("plist")
##
set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference)
set ocidPlistDict to (item 1 of listPlistDict)
if ocidPlistDict = (missing value) then
log "設定ファイルが見つかりません"
  ###ダイアログを出す
  set ocidValue to doSetTextDialogue(strBundleID)
  ##新規で設定ファイルを作成する
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidPlistDict's setValue:(ocidValue) forKey:(strKeyName)
  set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0)
  set listPlistData to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
  set ocidPlistData to (item 1 of listPlistData)
  #保存
  set listDone to ocidPlistData's writeToURL:(ocidPlistFilePathURL) options:0 |error|:(reference)
else
log "設定ファイルから設定を読み込みます"
  set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference)
  set ocidPlistDict to (item 1 of listPlistDict)
  set ocidValue to ocidPlistDict's valueForKey:(strKeyName)
  if ocidValue = (missing value) then
log "設定ファイルに値が見つかりません"
    ###ダイアログを出す
    set ocidValue to doSetTextDialogue(strBundleID)
ocidPlistDict's setValue:(ocidValue) forKey:(strKeyName)
    set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0)
    set listPlistData to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)
    set ocidPlistData to (item 1 of listPlistData)
    #保存
    set listDone to ocidPlistData's writeToURL:(ocidPlistFilePathURL) options:0 |error|:(reference)
  end if
end if
###設定項目の戻り
set strXid to ocidValue as text



####################
## ダイアログ
####################
to doSetTextDialogue(strBundleID)
  ## クリップボードの中身取り出し
  set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidPastBoardTypeArray to ocidPasteboard's types
  ###テキストがあれば
  set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
  if boolContain = true then
    ###値を格納する
    tell application "Finder"
      set strReadString to (the clipboard as text) as text
    end tell
    ###Finderでエラーしたら
  else
    set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
    if boolContain = true then
      set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
      set strReadString to ocidReadString as text
    else
      set strReadString to (strMes) as text
    end if
  end if
  ###ダイアログ
  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 ocidIconPathURL to doGetAppIconPathURL(strBundleID)
  set aliasIconPath to (ocidIconPathURL's absoluteURL()) as alias
  set recordResult to (display dialog strMes with title "入力してください" default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
  if "OK" is equal to (button returned of recordResult) then
    set strReturnedText to (text returned of recordResult) as text
  else if (gave up of recordResult) is true then
return "時間切れです"
  else
return "キャンセル"
  end if
  ###NSStringに格納
  set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
  ###タブと改行を除去しておく
  set ocidResponseTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidResponseTextM's appendString:(ocidResponseText)
  ##改行除去
  set ocidResponseTextM to ocidResponseTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
  set ocidResponseTextM to ocidResponseTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
  ##タブ除去
  set ocidResponseTextM to ocidResponseTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
  ##
return ocidResponseTextM
end doSetTextDialogue

####################
## アイコンURL取得
####################
to doGetAppIconPathURL(argBundleID)
  set strBundleID to argBundleID as text
  set ocidAppPathURL to doGetAppPathURL(strBundleID)
  if ocidAppPathURL is false then
log "アプリケーションが見つかりませんでした"
    set strIconPath to ("/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/FinderIcon.icns") as text
    set ocidIconPathStr to refMe's NSString's stringWithString:(strIconPath)
    set ocidIconPath to ocidIconPathStr's stringByStandardizingPath()
    set ocidFinderIconPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIconPath) isDirectory:false)
return ocidIconPathURL
  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 appFileManager to refMe's NSFileManager's defaultManager()
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
  ###ICONがみつかない時
  if boolExists is false then
return ocidFinderIconPathURL
  else
return ocidIconFilePathURL
  end if
end doGetAppIconPathURL

####################
## アプリケーションURL取得
####################
to doGetAppPathURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  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 strBundleID) 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
log "アプリケーションが見つかりませんでした"
return false
      end try
    end tell
  end if
return ocidAppPathURL
end doGetAppPathURL

|

[Finder]ファイルを1つだけ選択させたい(考え中)


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

#!/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 listRuleOut to {"ディスク作成フォルダ", "スマートフォルダ", "iOSパッケージのアーカイブ", "保存された検索クエリー", "定義済みの検索", "FTPインターネットロケーション", "AFP URL", "インターネットロケーション", "ファイルURL", "ファイルインターネットロケーション", "メールインターネットロケーション", "テキストクリッピング", "Webインターネットロケーション", "FTP URL", "AppleTalkインターネットロケーション", "AFPインターネットロケーション", "Appleデバイスのソフトウェアアップデートファイル", "Finder", "フォルダ", "NSLインターネットロケーション", "ピクチャクリッピング", "ニュースインターネットロケーション", "サウンドクリッピング", "クリッピング", "ボリューム", "ディスク作成フォルダ", "エイリアス"} as list


###選択項目は1つ限定
tell application "Finder"
  set listPath to selection as list
end tell
set numCntSelection to (count of listPath) as integer
if numCntSelection > 1 then
display alert "複数選択されている"
  set aliasFilePath to doChooseFile()
else if numCntSelection = 0 then
display alert "選択されていない"
  set aliasFilePath to doChooseFile()
else if numCntSelection = 1 then
log "1つ選択されている"
  set aliasFilePath to (item 1 of listPath) as alias
end if


###ファイル限定
tell application "Finder"
  set strKind to (kind of item aliasFilePath) as text
end tell

repeat with itemRuleOut in listRuleOut
  set strRuleOut to itemRuleOut as text
  if strRuleOut is strKind then
display alert "対象ファイルではない"
    set aliasFilePath to doChooseFile()
  end if
end repeat


return
set strDirPath to (POSIX path of aliasPath) as text


###ダイアログ
to doChooseFile()
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ##
  tell application "Finder"
    set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  end tell
  ############
  set listUTI to {"public.data", "public.content"} as list
  set strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  set aliasResponse 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
return aliasResponse
end doChooseFile

|

[choose from list]指定ディレクトリの中のファイル名を選択する(NSMutableDictionaryを使う)


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

#!/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 "Finder"
set aliasPathToMe to (path to me) as alias
end tell
###収集するコンテンツのディレクトリURL
set strPathToMe to (POSIX path of aliasPathToMe) as text
*)
set strSearchDirPath to "/System/Library/Desktop Pictures/Solid Colors"
set ocidSearchDirPathStr to refMe's NSString's stringWithString:(strSearchDirPath)
set ocidSearchDirPath to ocidSearchDirPathStr's stringByStandardizingPath()
set ocidSearchDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSearchDirPath) isDirectory:true)

###コンテンツを収集する 第一階層のみ
set appFileManager to refMe's NSFileManager's defaultManager()
##不可視ファイルを除く
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
##パスURLとファイル名を収集
set ocidForKey to refMe's NSArray's alloc()'s initWithArray:({(refMe's NSURLPathKey), (refMe's NSURLNameKey)})
set listFilePathURL to appFileManager's contentsOfDirectoryAtURL:(ocidSearchDirPathURL) includingPropertiesForKeys:{ocidForKey} options:(ocidOption) |error|:(reference)
set ocidFilePathURLArray to (item 1 of listFilePathURL)
##
set ocidFileNameDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
repeat with itemFilePathURL in ocidFilePathURLArray
  set ocidFileName to itemFilePathURL's lastPathComponent()
(ocidFileNameDict's setValue:(itemFilePathURL) forKey:(ocidFileName))
end repeat
set listFileName to (ocidFileNameDict's allKeys()) 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 listResponse to (choose from list listFileName with title "選んでください" with prompt "選んでください" default items (item 1 of listFileName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
###ダイアログの戻り値
set strFileName to (item 1 of listResponse) as text
###レコードから取り出す
set ocidFilePathURL to ocidFileNameDict's valueForKey:(strFileName)

set strFilePath to ocidFilePathURL's |path| as text
set strFilePath to ocidFilePathURL's absoluteString() as text
set aliasFilePath to (ocidFilePathURL's absoluteURL()) as alias



|

[choose from list]指定ディレクトリの中のファイル名を選択する


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

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

####################################

set strSearchDirPath to "/System/Library/Desktop Pictures/Solid Colors" as text
tell application "Finder"
  # set aliasPathToMe to (path to me) as alias
  # set aliasContainerDir to (container of aliasPathToMe) as alias
  # set aliasSearchDirPath to (folder "bin" of folder aliasContainerDir) as alias
  set aliasSearchDirPath to POSIX file strSearchDirPath as alias
  set listFilePath to every file of aliasSearchDirPath
  ###ファイル名リストとパスと入ったレコードを作成
  set listFileName to {} as list
  ###コンテンツの数だけ繰り返し
  repeat with itemFilePath in listFilePath
    set aliasFilePath to itemFilePath as alias
    set strFileName to (name of aliasFilePath) as text
    set end of listFileName to strFileName
  end repeat
end tell


###ダイアログを前面に出す
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 listFileName with title "選んでください" with prompt "選んでください" default items (item 1 of listFileName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strFileName to (item 1 of listResponse) as text
tell application "Finder"
  set aliasFilePath to (file strFileName of folder aliasSearchDirPath) as alias
end tell

set strFilePath to POSIX path of aliasFilePath as text
log strFilePath

|

mm→pix換算 解像度指定(途中)


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

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

###解像度指定
property numPPI : 144 as integer
###ダイアログのアイコンパス
property aliasIconPath : POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias


####デフォルトの値にクリップボードの中身を使う
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###ペーストボードのタイプにテキスト形式があればその値を使う
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###プレインテキストで受け取る
  set strReadString to (the clipboard as text)
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    ###プレインテキストにして受け取る
    set ocidReadString to appPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    ####テキスト形式がなかった場合のデフォルト値
    set strReadString to "72" as text
  end if
end if


###入力ダイアログの呼び出し strReadStringはデフォルト値
doCalculation(strReadString)

####ダイアログから値を受け取る場合
##set {numPX, numResponse} to doCalculation(strReadString)

##########################################
##入力ダイアログ サブ
##########################################
to doCalculation(numArgNo)
  ###受け取ったデフォルト値をテキストに確定させて
  set strReadString to numArgNo as text
  ##############################
  #####ダイアログを前面に出す
  ##############################
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder"
      activate
    end tell
  else
    tell current application
      activate
    end tell
  end if
  ###ダイアログ
  try
    set recordResult to (display dialog "mm数を半角数字で入力" with title "mm(" & numPPI & "ppi)→px" default answer strReadString buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 10 without hidden answer) as record
  on error
    ###エラーの場合falseを戻す
return false
  end try
  ###OKクリックしたら
  if "OK" is equal to (button returned of recordResult) then
    set strReturnedText to (text returned of recordResult) as text
  else if (gave up of recordResult) is true then
    ###エラーの場合falseを戻す
return false
  else
    ###エラーの場合falseを戻す
return false
  end if
  
  ###テキストに
  set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
  ####戻り値を半角にする
  set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
  set ocidResponseHalfwidth to (ocidResponseText's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
  set strResponse to ocidResponseHalfwidth as text
  set numResponse to strResponse as number
  set numInch to (numResponse / 25.4) as text
  set numChr to (count of numInch) as integer
  set numOffSet to (offset of "." in numInch) as integer
  if numOffSet is 0 then
    set numPX to (numInch * numPPI) as integer
  else if (numChr - numOffSet) = 1 then
    set numPX to (numInch * numPPI) as integer
  else
    set numPX to round (numInch * numPPI) as integer
  end if
  ##表示用のダイアログ呼び出し
doDialog({numPX, numResponse})
  ## return {numPX, numResponse}
end doCalculation

##########################################
##表示ダイアログ サブ
##########################################
to doDialog({numPX, numResponse})
  set strAns to ("" & numPX & " px") as text
  set strTitle to "計算結果です:" & numResponse & " mm →" & numPX & " px(" & numPPI & "ppi) " as text
  set strMes to ("" & strTitle & "\rpxピクセルには小数点以下は発生しないので四捨五入値です") as text
  try
    set recordResult to (display dialog strMes with title strTitle default answer strAns buttons {"クリップボードにコピー", "もう一度", "終了"} default button "終了" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
  on error
return "エラーしました"
  end try
  if button returned of recordResult is "終了" then
return "終了します"
  end if
  if (gave up of recordResult) is true then
return "時間切れです"
  end if
  if button returned of recordResult is "もう一度" then
    ###入力ダイアログに戻る 現在の計算結果を渡す
doCalculation(numResponse)
  end if
  if button returned of recordResult is "クリップボードにコピー" then
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    ##結果をペーストボードにテキストで入れる
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
return
  end if
return
end doDialog


return

|

display dialog

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

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

property refMe : a reference to current application

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807


################################
######ペーストボードを取得
################################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPasteboardArray to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
set ocidPasteboardStrings to (ocidPasteboardArray's objectAtIndex:0) as text

################################
######ダイアログ
################################
set aliasIconPath to POSIX file "/System/Applications/Preview.app/Contents/Resources/AppIcon.icns" as alias
set strDefaultAnswer to ocidPasteboardStrings as text
try
  set recordResponse to (display dialog "詳しく" with title "入力してください" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
  
on error
  log "エラーしました"
  return "エラーしました"
end try
if true is equal to (gave up of recordResponse) then
  return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of recordResponse) then
  set strResponse to (text returned of recordResponse) as text
else
  log "キャンセルしました"
  return "キャンセルしました"
end if

################################
######戻り値チェック
################################
###ダイアログの戻り値
set ocidResponse to (refMe's NSString's stringWithString:strResponse)
###数字以外があったらエラーで止める
###数字のキャラクタセット
set ocidDigitsCharSet to refMe's NSCharacterSet's decimalDigitCharacterSet()
###invertedSetで数字以外のキャラクタセット
set ocidNoDigitsCharSet to ocidDigitsCharSet's invertedSet()
###数値以外の文字のレンジを求めて
set recordRenge to ocidResponse's rangeOfCharacterFromSet:ocidNoDigitsCharSet
###見つからない以外=見つかった場合は数字以外の文字がある
if (recordRenge's location) ≠ refNSNotFound then
  return "数字以外の文字が含まれています"
else
  log "数字だけです"
end if
############################
####戻り値を半角にする
set ocidResponseHalfwidth to (ocidResponse's stringByApplyingTransform:(refMe's NSStringTransformFullwidthToHalfwidth) |reverse|:false)
################################
####文字数数える
set numCntResponseText to ocidResponseHalfwidth's |length|()
####4文字の戻り値以外なら終了
if numCntResponseText ≠ 4 then
  log "文字数誤り"
  return "文字数誤り"
end if




log ocidResponseHalfwidth as text



|

[Bonjour service types]choose URL のSMB接続用プロパティ

list of Bonjour service types being used by Mac OS X
https://developer.apple.com/library/archive/qa/qa1312/
ここに掲載が無いSMBは
『_smb._tcp』

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


set listURL to {"_ssh._tcp", "_ftp._tcp", "_nfs._tcp", "_afpovertcp._tcp", "_http._tcp", "_ipp._tcp", "_smb._tcp"} as list

set listURL to {"_afpovertcp._tcp", "_smb._tcp"} as list


set strResults to choose URL showing listURL with editable URL

こんな感じになります


Table 1  Bonjour service types.

Protocol Name

Service Type

Notes

AppleTalk Filing Protocol (AFP)

_afpovertcp._tcp

Used by Personal File Sharing in theSharing preference panel starting in Mac OS X 10.2. The Finder browses for AFP servers startingin Mac OS X 10.2.

Network File System (NFS)

_nfs._tcp

The Finder browses for NFS serversstarting in Mac OS X 10.2.

WebDAV File System (WEBDAV)

_webdav._tcp

The Finder browses for WebDAV serversbut because of a bug (r. 3171023), double-clicking a discovered server fails to connect.

File Transfer Protocol (FTP)

_ftp._tcp

Used by FTP Access in the Sharingpreference panel starting in Mac OS X 10.2.2. The Finder browses for FTP servers starting in MacOS X 10.3. The Terminal application also browses for FTP servers starting in Mac OS X10.3.

Secure Shell (SSH)

_ssh._tcp

Used by Remote Login in the Sharingpreference panel starting in Mac OS X 10.3. The Terminal application browses for SSH serversstarting in Mac OS X 10.3.

Remote AppleEvents

_eppc._tcp

Used by Remote AppleEvents in theSharing preference panel starting in Mac OS X 10.2.

Hypertext Transfer Protocol(HTTP)

_http._tcp

Used by Personal Web Sharing in theSharing preference panel to advertise the User's Sites folders starting in Mac OS X 10.2.4.Safari can be used to browse for web servers.

Remote Login (TELNET)

_telnet._tcp

If Telnet is enabled, xinetd willadvertise it via Bonjour starting in Mac OS X 10.3. The Terminal application browses for Telnetservers starting in Mac OS X 10.3.

Line Printer Daemon (LPD/LPR)

_printer._tcp

Print Center browses for LPR printersstarting in Mac OS X 10.2. For more information on creating a Bonjour printer, please see theBonjour Printing Specification.

Internet Printing Protocol (IPP)

_ipp._tcp

Print Center browses for IPP printersstarting in Mac OS X 10.2. For more information on creating a Bonjour printer, please see theBonjour Printing Specification.

PDL Data Stream (Port 9100)

_pdl-datastream._tcp

Print Center browses for PDL Data Streamprinters starting in Mac OS X 10.2. For more information on creating a Bonjour printer, pleasesee the Bonjour Printing Specification.

Remote I/O USB Printer Protocol

_riousbprint._tcp

Used by the AirPort Extreme Base Stationto share USB printers. Printer Setup Utility browses for AirPort Extreme shared USB printerswhich use the Remote I/O USB Printer Protocol starting in Mac OS X 10.3.

Digital Audio Access Protocol(DAAP)

_daap._tcp

Also known as iTunes Music Sharing.iTunes advertises and browses for DAAP servers starting in iTunes 4.0.

Digital Photo Access Protocol(DPAP)

_dpap._tcp

Also known as iPhoto Photo Sharing.iPhoto advertises and browses for DPAP servers starting in iPhoto 4.0.

iChat Instant Messaging Protocol

_ichat._tcp

Used by iChat 1.0 which shipped with MacOS X 10.2. This service is now deprecated with the introduction of the "presence" service iniChat AV. See below.

iChat Instant Messaging Protocol

_presence._tcp

Used by iChat AV which shipped with MacOS X 10.3.

Image Capture Sharing

_ica-networking._tcp

Used by the Image Capture application toshare cameras in Mac OS X 10.3.

AirPort Base Station

_airport._tcp

Used by the AirPort Admin Utilitystarting in Mac OS X 10.2 in order to locate and configure the AirPort Base Station (DualEthernet) and the AirPort Extreme Base Station.

Xserve RAID

_xserveraid._tcp

Used by the Xserve RAID Admin Utility tolocate and configure Xserve RAID hardware.

Distributed Compiler

_distcc._tcp

Used by Xcode in its Distributed Buildsfeature.

Apple Password Server

_apple-sasl._tcp

Used by Open Directory Password Serverstarting in Mac OS X Server 10.3.

Workgroup Manager

_workstation._tcp

Open Directory advertises this servicestarting in Mac OS X 10.2. Workgroup Manager browses for this service starting in Mac OS XServer 10.2.

Server Admin

_servermgr._tcp

Mac OS X Server machines advertise thisservice starting in Mac OS X 10.3. Server Admin browses for this service starting in Mac OS XServer 10.3.

Remote Audio Output Protocol(RAOP)

_raop._tcp

Also known as AirTunes. The AirPortExpress Base Station advertises this service. iTunes browses for this service starting in iTunes4.6.

|

[choose from list]選択ファイルを開く

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

######このスクリプトのパス
set aliasPathToMe to path to me as alias
######ファインダ
tell application "Finder"
#####コンテナディレクトリ
set aliasContainer to container of aliasPathToMe as alias
#####スクリプトフォルダ-->この中のファイルを参照します
set aliasScriptDir to folder "Scripts" of folder aliasContainer as alias
end tell
#######フォルダ内のファイルの名前を取得
tell application "Finder"
set listScripts to name of every item of aliasScriptDir as list
end tell
#####ファイル名のリストでダイアログ
try
set objResponse to (choose from list listScripts with title "選んでください" with prompt "開くスクリプトを選んでください" default items (item 1 of listScripts) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponse is false then
log "キャンセルしました"
return
end if
######選んだ戻り値
set strResponse to (objResponse) as text
######フォルダパスをつなげてファイルパスにする
tell application "Finder"
set aliasFilePath to file strResponse of folder aliasScriptDir
end tell
######↑ここで整形したファイルを開く
try
tell application "Script Editor"
launch
activate
open aliasFilePath
end tell
on error

tell application "Finder"
set aliasDefaultLocation to container of (path to me) as alias
end tell
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type {"com.apple.applescript.script", "com.apple.applescript.text"} with invisibles and showing package contents without multiple selections allowed) as alias

tell application "Script Editor"
launch
activate
open aliasFilePath

end tell

end try

|

[display dialog]パスワードの入力を求める



set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Actions.icns") as alias
set strDialogText to "管理者パスワードが必要です"
set strDefaultAns to "123455"
set listButton to {"実行", "キャンセル"} as list

set objResponse to display dialog strDialogText buttons listButton default button 2 cancel button 2 default answer strDefaultAns with title strDialogText with icon aliasIconPass giving up after 10 with hidden answer

if (gave up of objResponse) is true then
return "時間切れになりました"
error number -128
else if (button returned of objResponse) is "キャンセル" then
return "キャンセルしました"
error number -128
else
set strPassWord to (text returned of objResponse) as text
end if

|

その他のカテゴリー

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