所以我有苹果脚本:
-- Uses the satimage osax
-- Get it at http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html
tell application "Music"
try
set the_tracks to the selection
repeat with a_track in the_tracks
set the_old_name to name of a_track as string
set the_new_name to titlecase the_old_name
set the name of a_track to the_new_name
log the_old_name
log the_new_name
end repeat
on error
set the_tracks to the selection
repeat with a_track in the_tracks
set the_old_name to name of a_track as string
set the_new_name to titlecase the_old_name
set the name of a_track to the_new_name
log the_old_name
log the_new_name
end repeat
end try
end tell
而且我希望能够更改字符串/标题中单个元素的大小写。专门将罗马数字更改为所有大写字母,在本示例中为“ Iv”。并将其更改为“ IV”:
来自:G小调协奏曲格罗索8号,作品 6,《圣诞节协奏曲》:四。维瓦
至:G小调协奏曲格罗索第八号,作品。6,《圣诞节协奏曲》:四。维瓦
任何帮助将不胜感激。谢谢!
此处理程序将所有罗马字符从I替换为IX,后跟一个句点,并使用等价的大写字母代替。它使用了Foundation框架中强大的API
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
on uppercaseRomanCharacters(theText)
set cocoaString to current application's NSString's stringWithString:theText
set romanRange to cocoaString's rangeOfString:"(I{1,3}|IX|IV|VI{0,3})\\." options:1025
if romanRange's location < cocoaString's |length|() then
set substring to cocoaString's substringWithRange:romanRange
return (cocoaString's stringByReplacingCharactersInRange:romanRange withString:(substring's uppercaseString())) as text
end if
return theText
end uppercaseRomanCharacters
set theString to "Concerto Grosso No. 8 in G Minor, Op. 6, \"Christmas Concerto\": iv. Vivace"
set newName to uppercaseRomanCharacters(theString)
您可以在循环中使用它
repeat with a_track in the_tracks
set the_old_name to name of a_track -- as string is redundant
set the_new_name to my uppercaseRomanCharacters(the_old_name)
set the name of a_track to the_new_name
log the_old_name
log the_new_name
end repeat
处理程序必须位于脚本顶层的某个位置。
注意:1025是选项的整数值 NSCaseInsensitiveSearch | NSRegularExpressionSearch
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句