AppleScript List

ファイル名の英数小文字を大文字にする


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


(*
旧OS用なので
Objective-cを使わないクラシックな処理
shellも使わない
*)
###ダブルクリックして開いたら?
on run
  set strMes to "選んでください"
  set aliasDefaultsLocation to (POSIX file "/Users/Shared/Downloads") as alias
  set listUTI to {"public.movie", "public.mpeg-4", "public.mpeg-4-audio", "com.apple.quicktime-movie"} as list
  set listAliasFilePath to (open (choose file strMes default location aliasDefaultsLocation with prompt strMes of type listUTI with invisibles and multiple selections allowed without showing package contents)) as list
open
end run

###ドロップレットの始まり
on open listAliasFilePath
  ###受け取ったエイリアスの数だけ繰り返し
  repeat with itemAliasFilePath in listAliasFilePath
    set aliasFilePath to itemAliasFilePath as alias
    ###フォルダチェック
    tell application "Finder"
      set strKind to (kind of aliasFilePath) as text
    end tell
    ###
    if strKind is "フォルダ" then
      log "フォルダは処理しない"
    else
      ###ファイルは処理する
      tell application "Finder"
# set aliasContainerDirPath to (container of aliasFilePath) as alias
###ファイル名と拡張子名
set strFileName to (name of aliasFilePath) as text
set strExtension to (name extension of aliasFilePath) as text
      end tell
      ###ファイル名からベースファイル名を取得
      set AppleScript's text item delimiters to "."
      set listFileName to every text item of strFileName
      set AppleScript's text item delimiters to ""
      set numCntChar to (count of listFileName) as integer
      set strBaseFileName to ("") as text
      repeat with itemIntNo from 1 to (numCntChar - 1) by 1
set strBaseFileName to (strBaseFileName & (item itemIntNo of listFileName)) as text
      end repeat
      ###本処理 小文字を大文字に
      set listLowerAlphabet to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} as list
      set listUpperAlphabet to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} as list
      set AppleScript's text item delimiters to ""
      set listNewFileName to every text item of strTmpBaseFileName
      set AppleScript's text item delimiters to ""
      #変更後のファイル名
      set strNewFileName to ("") as text
      #全文字繰り返し
      repeat with itemNewFileName in listNewFileName
#テキストに
set strItemNewFileName to itemNewFileName as text
#小文字リストに値があれば処理する
if listLowerAlphabet contains strItemNewFileName then
#小文字リストの何番目?
set cntNo to doOffsetInList(strItemNewFileName, listLowerAlphabet) as integer
#大文字リストから大文字を取り出してファイル名にする
set strItemNewFileName to (item cntNo of listUpperAlphabet) as text
end if
#変換した文字も変換しない文字も積み上げていく
set strNewFileName to (strNewFileName & strItemNewFileName) as text
      end repeat
      ##拡張子を加えて最終的な変更後のファイル名
      set strNewFileName to (strNewFileName & "." & strExtension) as text
      tell application "Finder"
tell file aliasFilePath
###ファイル名の変更
set name to strNewFileName
end tell
      end tell
    end if
  end repeat
end open



##################
#リストの何番目?
##################
to doOffsetInList(argText, argList)
  set numCntPosition to 1 as integer
  repeat with itemChooser in argList
    set strItemChooser to itemChooser as text
    if strItemChooser is argText then
      set numCntOffset to numCntPosition as integer
    end if
    set numCntPosition to numCntPosition + 1 as integer
  end repeat
return numCntOffset
end doOffsetInList
##################
#文字の置換
##################
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace


|

[リスト]list基本


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

set listArray to {"AAA", "BBB", "CCC", "DDD"} as list
###項目の有無
if listArray contains "CCC" then
  log "リストの中に値があります"
end if
###項目の有無
set boolContains to (listArray contains "CCC") as boolean
if boolContains is true then
  log "リストの中に値があります"
end if
###項目の有無
if "CCCCCCCC" is in listArray then
  log "リストの中に値があります"
else
  log "リストの中に値がありません"
end if
###項目の有無
set boolIsIn to ("CCCCCCCC" is in listArray) as boolean
if boolIsIn is true then
  log "リストの中に値があります"
else
  log "リストの中に値がありません"
end if


###最初の
log item 1 of listArray
-->(*AAA*)

###2番目と3番目
log items 2 thru 3 of listArray
-->(*BBB, CCC*)

###2番目から最後まで
log items 2 thru (last item) of listArray
-->(*BBB, CCC, DDD*)

###最初の
log (first item) of listArray
-->(*AAA*)

###2番目の
log (second item) of listArray
-->(*BBB*)

###最後の
log (last item) of listArray
-->(*DDD*)

##後ろから 1番目
log item -1 of listArray
-->(*DDD*)

##後から2番目から最後まで
log items -2 thru (last item) of listArray
-->(*CCC, DDD*)

##後から2番目から最初まで
log items -2 thru (first item) of listArray
-->(*AAA, BBB, CCC*)

##後に追加
copy "EEE" to end of listArray
-->(*AAA, BBB, CCC, DDD, EEE*)

##後に追加
set end of listArray to "FFF"
-->(*AAA, BBB, CCC, DDD, EEE, FFF*)

###項目追加して新しいリストに
set listNewList to (listArray & "GGG") as list
-->{"AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG"}

###値の変更 最初の項目
set (first item) of listNewList to "aaa"
-->(*aaa, BBB, CCC, DDD, EEE, FFF, GGG*)





|

リストの値を入れ替える

リストの各値を10づつ加算します

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

###オフセット値
set numOffSet to 10 as integer
###最初のウィンドウの位置
set listBounds to {0, 25, 620, 360} as list


###ウィンドウの数だけ繰返し
repeat 20 times
  
  ###ウィンドウの位置を次のウィンドウ用に加算
  ###値を取って
  set numFirst to (first item of listBounds) as integer
  set numSecond to (second item of listBounds) as integer
  set numThird to (third item of listBounds) as integer
  set numFourth to (fourth item of listBounds) as integer
  ###加算して
  set numFirst to numFirst + numOffSet as integer
  set numSecond to numSecond + numOffSet as integer
  set numThird to numThird + numOffSet as integer
  set numFourth to numFourth + numOffSet as integer
  ###リストに戻す
  set (first item of listBounds) to numFirst as integer
  set (second item of listBounds) to numSecond as integer
  set (third item of listBounds) to numThird as integer
  set (fourth item of listBounds) to numFourth as integer
  
  log listBounds
  -->
  (*10, 35, 630, 370*)
  (*20, 45, 640, 380*)
  (*30, 55, 650, 390*)
  (*40, 65, 660, 400*)
  (*50, 75, 670, 410*)
  (*60, 85, 680, 420*)
  (*70, 95, 690, 430*)
  (*80, 105, 700, 440*)
  (*90, 115, 710, 450*)
  (*100, 125, 720, 460*)
  (*110, 135, 730, 470*)
  (*120, 145, 740, 480*)
  (*130, 155, 750, 490*)
  (*140, 165, 760, 500*)
  (*150, 175, 770, 510*)
  (*160, 185, 780, 520*)
  (*170, 195, 790, 530*)
  (*180, 205, 800, 540*)
  (*190, 215, 810, 550*)
  (*200, 225, 820, 560*)
  
end repeat

|

[List]リストの何番目?



set listSmaple to {"AA", "BB", "CC", "DD", "EE", "FF", "", "GG"} as list


set strSerchText to "DD" as text


log doOffsetInList(strSerchText, listSmaple)

-->(*4*)


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

######リストの何番目?サブ

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


to doOffsetInList(argText, argList)

  set numCntPosition to 1 as integer

  repeat with itemChooser in argList

    set strItemChooser to itemChooser as text

    if strItemChooser is argText then

      set numCntOffset to numCntPosition as integer

    end if

    set numCntPosition to numCntPosition + 1 as integer

  end repeat

  return numCntOffset

end doOffsetInList

|

[リスト]list基本

set listArray to {"AAA", "BBB", "CCC", "DDD"} as list

log item 1 of listArray
-->(*AAA*)

log items 2 thru 3 of listArray
-->(*BBB, CCC*)

log items 2 thru (last item) of listArray
-->(*BBB, CCC, DDD*)

log (first item) of listArray
-->(*AAA*)

log (second item) of listArray
-->(*BBB*)

log (last item) of listArray
-->(*DDD*)

##マイナスは後ろから
log item -1 of listArray
-->(*DDD*)

##マイナスは後ろから
log item -2 of listArray
-->(*CCC*)

|

[Basic]リスト形式色々

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

####ログ表示
doLogView()


###テキストが入っているリスト
set listOfText to {"AAA", "BBB", "CCC", "DDD", "EEE"} as list

###数値が入っているリスト
set listOfNumber to {1, 2, 3, 4, 5} as list

###リストの中にリストが入ってるリスト
set listOfDouble to {listOfText, listOfNumber} as list
-->{{"AAA", "BBB", "CCC", "DDD", "EEE"} ,{1, 2, 3, 4, 5} }

###リストの中にレコードが入ってるリスト
set recordA to {UserName:"林檎太郎", UserAge:23} as record
set recordB to {UserName:"大江須二郎", UserAge:24} as record

set listOfRecord to {recordA, recordB} as list
log listOfRecord as list
-->(*UserName:林檎太郎, UserAge:23, UserName:大江須二郎, UserAge:24*)

###################
##ディスクオブジェクトのリスト
tell application "System Events"
set listDisk to every disk
end tell
--> {disk id "Macintosh HD,-100,2", disk id "VM,-101,2", disk id "Preboot,-102,2", disk id "Update,-103,2", disk id "xarts,-104,2", disk id "iSCPreboot,-105,2", disk id "Hardware,-106,2", disk id "home,-107,2"}
log item 1 of listDisk

###################
##オブジェクへの参照のリスト
tell application "Finder"
tell folder (path to music folder from user domain)
set listObjAlias to (every item) as list
end tell
end tell
log item 1 of listObjAlias as alias
--> (*alias Macintosh HD:Users:XXXXXXXXXXX:Music:Music:*)

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

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

|

その他のカテゴリー

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