AppleScript XML OPML

OPMLのxmlURLを参照して、ファイルが見つからない項目を削除する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# OPMLの404見つからない と 300移動をリストにします
# 項目の削除もできます
#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()

#############################
###設定項目
# 404ステータスのRSSを削除するか?
set boolDel404 to true as boolean
# 30xステータスのRSSを削除するか?
set boolDel300 to false as boolean


#############################
###ダイアログを前面に出す
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 appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
tell application "Finder"
  set aliasDefaultLocation to container of (path to me) as alias
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell

############UTIリスト
set listUTI to {"public.xml", "public.rss", "public.opml", "dyn.ah62d4rv4ge8086drru"}

set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath 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
on error
log "エラーしました"
return "エラーしました"
end try

set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
####################
#【保存】パス
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("edit.opml")
set ocid404FilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("404リスト.txt")
set ocid301FilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("301リスト.txt")
####################
set ocidOption to (refMe's NSXMLDocumentTidyXML)
set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference))
###XMLドキュメント
set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
###ROOTエレメント
set ocidRootElement to ocidReadXMLDoc's rootElement()
set ocidHeadElement to (ocidRootElement's elementsForName:("head"))'s firstObject()
set ocidHeadCopy to ocidHeadElement's XMLString()
###bodyエレメント
set ocidBody to (ocidRootElement's elementsForName:("body"))'s firstObject()
set ocidBodyCopy to ocidBody's XMLString()

####################
#【保存】XML初期化
set ocidSaveXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidSaveXMLDoc's setVersion:("1.0")
ocidSaveXMLDoc's setCharacterEncoding:("utf-8")
ocidSaveXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)
#【保存】ROOT
set ocidSaveRootElement to refMe's NSXMLElement's elementWithName:("opml")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0")
ocidSaveRootElement's addAttribute:(ocidAddNode)
#【保存】HEAD
set ocidSaveHeadElement to refMe's NSXMLElement's alloc()'s initWithXMLString:(ocidHeadCopy) |error|:(missing value)
#【保存】BODY
set ocidSaveBodyElement to refMe's NSXMLElement's alloc()'s initWithXMLString:(ocidBodyCopy) |error|:(missing value)
####################
set numCntBodyChild to ocidSaveBodyElement's childCount() as integer
set list404 to {} as list
set list300 to {} as list
###親=フォルダ の数だけ繰り返し
repeat with itemIntNo from 0 to (numCntBodyChild - 1) by 1
  set ocidOutLineParent to (ocidSaveBodyElement's childAtIndex:(itemIntNo))
  set numCntOutLineParent to ocidOutLineParent's childCount() as integer
  ###子=各RSSのURL要素の数だけ繰り返し
  repeat with itemIntCildNo from (numCntOutLineParent - 1) to 0 by -1
    set ocidOutLineChild to (ocidOutLineParent's childAtIndex:(itemIntCildNo))
    set ocidContXmlUrlAttr to (ocidOutLineChild's attributeForName:("xmlUrl"))
    set ocidXMLURL to ocidContXmlUrlAttr's stringValue()
    set ocidURLString to (refMe's NSString's stringWithString:(ocidXMLURL))
    #302対策でHTTPをHTTPSに置き換えておく
    set ocidSetURL to (ocidURLString's stringByReplacingOccurrencesOfString:("http:") withString:("https:"))
    set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidSetURL))
    #生存確認
    set strURL to ocidURL's absoluteString() as text
    set strCommandText to ("/usr/bin/curl -s -o /dev/null -w \"%{http_code}\" \"" & strURL & "\" --connect-timeout 5 --max-time 10") as text
    try
      set strResponse to (do shell script strCommandText) as text
    on error
      #ドメイン落ちしている場合
      set strResponse to ("404") as text
    end try
    if strResponse is "404" then
      set end of list404 to strURL
      if boolDel404 is true then
        #対象の子要素を削除
(ocidOutLineParent's removeChildAtIndex:(itemIntCildNo))
      end if
    else if strResponse is "301" then
      set end of list300 to strURL
      if boolDel300 is true then
        #対象の子要素を削除
(ocidOutLineParent's removeChildAtIndex:(itemIntCildNo))
      end if
    else if strResponse is "302" then
      set end of list300 to strURL
      if boolDel300 is true then
        #対象の子要素を削除
(ocidOutLineParent's removeChildAtIndex:(itemIntCildNo))
      end if
    end if
    
  end repeat
  
end repeat
####################
#別に取得した404リストと300リストをテキストで保存
##リストを改行区切りテキストに変更
set ocid404Array to refMe's NSArray's arrayWithArray:(list404)
set ocid301Array to refMe's NSArray's arrayWithArray:(list300)
set ocid404Text to ocid404Array's componentsJoinedByString:("\n")
set ocid301Text to ocid301Array's componentsJoinedByString:("\n")
#保存
set listDone to ocid404Text's writeToURL:(ocid404FilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
set listDone to ocid301Text's writeToURL:(ocid301FilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####################
#編集済みのエレメントをテキストにして
set ocidEditBody to ocidSaveBodyElement's XMLString()
#編集済みエレメントにしてから
set listEditBodyElement to refMe's NSXMLElement's alloc()'s initWithXMLString:(ocidEditBody) |error|:(reference)
set ocidEditBodyElement to (item 1 of listEditBodyElement)
##rootにセットして
ocidSaveRootElement's addChild:(ocidSaveHeadElement)
ocidSaveRootElement's addChild:(ocidEditBodyElement)
ocidSaveXMLDoc's setRootElement:(ocidSaveRootElement)
##########
#【保存】読み取りやすい表示
set ocidXMLdata to ocidSaveXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
#保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)


|

[OPML]NHKのRSSをOPMLにする(入力にレコードを使う)

ダウンロード - nhknewsrss.zip


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

#!/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
set appFileManager to refMe's NSFileManager's defaultManager()

###設定項目
set strBaseURL to ("https://www.nhk.or.jp/rss/news/") as text
##ファイル名デスクトップが保存先
set strSaveFileName to ("NHKOpml.opml") as text
##OPMLのタイトル
set strTitle to ("QuickTimerのOPML") as text
##outlineエレメント名=feedlyだとフォルダ名
set strOutlineName to ("NHK RSS") as text
##ファイル名と名前をレコードにしておく
set recordFileName to {|主要|:"cat0.xml", |社会|:"cat1.xml", |文化|:"cat2.xml", |科学|:"cat3.xml", |政治|:"cat4.xml", |経済|:"cat5.xml", |国際|:"cat6.xml", |スポーツ|:"cat7.xml", |LIVE|:"cat-live.xml"} as record
##DICTに入れて
set ocidFileNameDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidFileNameDict's setDictionary:(recordFileName)
##キーリストにしておく
set ocidAllKeys to ocidFileNameDict's allKeys()
########################
##保存先パス
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
##保存ファイルパス
set ocidOpmlFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
########################
##XML
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"opml"
###【A-1】ROOT エレメントにネームスペース
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0"))
###【A-B】子要素
set ocidHeadElement to (refMe's NSXMLElement's alloc()'s initWithName:("head"))
###【A-B-1】子要素
set ocidTitleElement to (refMe's NSXMLElement's elementWithName:("title"))
(ocidTitleElement's setStringValue:(strTitle))
##子要素titleエレメント をheadにセット
(ocidHeadElement's addChild:(ocidTitleElement))
##↑で追加したheadエレメントをROOTにセット
(ocidRootElement's addChild:(ocidHeadElement))
###【A-C-1】子要素body
set ocidBodyElement to (refMe's NSXMLElement's alloc()'s initWithName:("body"))
##【A-C-2】bodyエレメントの外側のoutline=フォルダ名になる
set ocidOutLineDivElement to (refMe's NSXMLElement's elementWithName:("outline"))
##外側のoutlineにネームスペース text とtitleを追加
(ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("rss")))
(ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:(strOutlineName)))
(ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:(strOutlineName)))
###【A-C-3】子要素 項目
repeat with itemAllKeyArray in ocidAllKeys
  ##【A-C-3】子要素の各ITEM
  set ocidOutLineElement to (refMe's NSXMLElement's elementWithName:("outline"))
  ##ネームスペース text とtitleを追加
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("rss")))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:(itemAllKeyArray)))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemAllKeyArray)))
  #URLをセット
  set strItemURL to (ocidFileNameDict's valueForKey:(itemAllKeyArray)) as text
  set strSetURL to (strBaseURL & strItemURL) as text
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xmlUrl") stringValue:(strSetURL)))
  #リンクをセット
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("htmlUrl") stringValue:("https://www3.nhk.or.jp/news/")))
  #####外側のoutlineエレメントをbodyエレメントに追加
(ocidOutLineDivElement's addChild:(ocidOutLineElement))
end repeat
##個別で1つだけ別でセット
set strRssURL to ("https://www.nhk.or.jp/blog-blog/last20.xml") as text
set strLinkURL to ("https://www.nhk.or.jp/blog-blog/") as text
set ocidOutLineElement to (refMe's NSXMLElement's elementWithName:("outline"))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("rss")))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:("BLOG")))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("BLOG")))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xmlUrl") stringValue:(strRssURL)))
(ocidOutLineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("htmlUrl") stringValue:(strLinkURL)))
(ocidOutLineDivElement's addChild:(ocidOutLineElement))

###外側のOutLineをBodyにセットしてから
(ocidBodyElement's addChild:(ocidOutLineDivElement))
###bodyエレメントをROOTにセット
(ocidRootElement's addChild:(ocidBodyElement))
###【XML】↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントにする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidOpmlFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

return




|

[Opml]YahooNewsのRSSのOPML(入力にJSONを使う)

ダウンロード - yahoonewsrss.zip


ダウンロード - yahoonewsopml.opml


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 別途JSONが必要です
# 使う場合は以下を利用ください(JSONも同封しています)
(*
https://quicktimer.cocolog-nifty.com/icefloe/files/yahoonewsrss.zip
*)
# 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
set appFileManager to refMe's NSFileManager's defaultManager()

###設定項目
set strBaseURL to ("https://news.yahoo.co.jp") as text
##ファイル名デスクトップが保存先
set strSaveFileName to ("YahooNewsOpml.opml") as text
##OPMLのタイトル
set strTitle to ("QuickTimerのOPML") as text
##outlineエレメント名=feedlyだとフォルダ名
set strOutlineName to ("YahooNewsRss") as text

########################
##保存先パス
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
##保存ファイルパス
set ocidOpmlFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
########################
##JSONファイル
set strJsonFileName to ("rssList.json") as text
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
  set aliasJsonFilePath to (file strJsonFileName of folder "data" of folder aliasContainerDirPath) as alias
end tell
set strJsonFilePath to (POSIX path of aliasJsonFilePath) as text
set ocidJsonFilePathStr to refMe's NSString's stringWithString:(strJsonFilePath)
set ocidJsonFilePath to ocidJsonFilePathStr's stringByStandardizingPath()
set ocidJsonFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidJsonFilePath) isDirectory:false)
##JSON読みとり
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidJsonFilePathURL) options:(ocidOption) |error|:(reference)
set ocidReadData to (item 1 of listReadData)
#NSPropertyListSerializationしてレコードに
set ocidOption to (refMe's NSJSONReadingMutableContainers)
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidReadData) options:(ocidOption) |error|:(reference))
set ocidPlistDict to item 1 of listJSONSerialization
###ALLkey取得
set ocidAllKeyArray to ocidPlistDict's allKeys()
########################
##XML
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"opml"
###【A-1】ROOT エレメントにネームスペース
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0"))
###【A-B】子要素
set ocidHeadElement to (refMe's NSXMLElement's alloc()'s initWithName:("head"))
###【A-B-1】子要素
set ocidTitleElement to (refMe's NSXMLElement's elementWithName:("title"))
(ocidTitleElement's setStringValue:(strTitle))
##子要素titleエレメント をheadにセット
(ocidHeadElement's addChild:(ocidTitleElement))
##↑で追加したheadエレメントをROOTにセット
(ocidRootElement's addChild:(ocidHeadElement))
###【A-C-1】子要素body
set ocidBodyElement to (refMe's NSXMLElement's alloc()'s initWithName:("body"))
###【A-C-2】子要素 項目フォルダ
repeat with itemAllKeyArray in ocidAllKeyArray
  ##【A-C-2】bodyエレメントの外側のoutline=フォルダ名になる
  set ocidOutLineDivElement to (refMe's NSXMLElement's elementWithName:("outline"))
  ##外側のoutlineにネームスペース text とtitleを追加
(ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:(itemAllKeyArray)))
(ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemAllKeyArray)))
  set ocidDivArray to (ocidPlistDict's objectForKey:(itemAllKeyArray))
  ##【A-D】各項目=RSSの項目の処理
  repeat with itemDivDict in ocidDivArray
    #名前をセット
    set strItemName to (itemDivDict's valueForKey:("name"))
    set ocidOutLineItemElement to (refMe's NSXMLElement's elementWithName:("outline"))
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("rss")))
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:(strItemName)))
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:(strItemName)))
    #URLをセット
    set strItemURL to (itemDivDict's valueForKey:("url")) as text
    set strSetURL to (strBaseURL & strItemURL) as text
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xmlUrl") stringValue:(strSetURL)))
    #リンクをセット
    set ocidSetURLString to (refMe's NSString's stringWithString:(strSetURL))
    ##rssの部分のパスを削除して
    set ocidSetURL to (ocidSetURLString's stringByReplacingOccurrencesOfString:("/rss/") withString:("/"))
    set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidSetURL))
    ##XMLファイル名を削除して
    set ocidWebLinkURL to ocidURL's URLByDeletingLastPathComponent()
    ##そのURLをセットする
    set strWebLinkURL to ocidWebLinkURL's absoluteString() as text
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("htmlUrl") stringValue:(strWebLinkURL)))
    ##内側アイテムoutlineエレメントを 外側のoutlineエレメントにセットしていく
(ocidOutLineDivElement's addChild:(ocidOutLineItemElement))
  end repeat
  #####外側のoutlineエレメントをbodyエレメントに追加
(ocidBodyElement's addChild:(ocidOutLineDivElement))
end repeat
###bodyエレメントをROOTにセット
(ocidRootElement's addChild:(ocidBodyElement))
###【XML】↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントにする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidOpmlFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

return




|

[OPML]Adobe Community Opml 全カテゴリ

ダウンロード - adobe20community20opml.zip


全投稿対象と新規投稿のみの2種類

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

#!/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
set appFileManager to refMe's NSFileManager's defaultManager()

###設定項目
##ファイル名デスクトップが保存先
set strSaveFileName to ("Adobe Community ALL Post Opml.opml") as text
##OPMLのタイトル
set strTitle to ("QuickTimerのOPML") as text
##outlineエレメント名=feedlyだとフォルダ名
set strOutlineName to ("Adobe Community JP All Post") as text


set listCategoryIDJp to {"ct-acrobat-reader-and-reader-mobile-jp", "ct-indesign-jp", "ct-illustrator-jp", "ct-after-effects-jp", "ct-acrobat-jp", "ct-photoshop-jp", "ct-premiere-elements-jp", "ct-premiere-pro-jp", "ct-fireworks-jp", "ct-adobe-express-jp", "ct-animate-jp", "ct-xd-jp", "ct-lightroom-classic-jp", "ct-photoshop-express-jp", "ct-lightroom-jp", "ct-video-hardware-jp", "ct-photoshop-elements-jp", "ct-premiere-rush-jp", "ct-media-encoder-jp", "ct-cc-services-jp", "ct-download-and-install-jp", "ct-stock-jp", "ct-fresco-jp", "ct-dreamweaver-jp", "ct-account-payment-and-plan-jp", "ct-perpetual-jp", "ct-bridge-jp", "ct-photoshop-beta-jp", "ct-audition-jp", "ct-community-help-jp", "ct-character-animator-jp", "ct-muse-jp", "ct-teams-jp", "ct-adbe-sign-and-dc-pdf-services-jp", "ct-fonts-jp", "ct-captivate-jp", "ct-adobe-scan-jp", "ct-camera-raw-jp", "ct-framemaker-jp", "ct-enterprise-jp", "ct-color-jp", "ct-robohelp-jp", "ct-dimension-jp", "ct-flash-player-and-shockwave-player-jp", "ct-photoshop-camera-jp", "ct-contribute-jp", "ct-photoshop-mix-jp", "ct-digital-editions-jp", "ct-comp-jp", "ct-spark-jp", "ct-capture-jp", "ct-prelude-jp", "ct-photoshop-sketch-jp", "ct-photoshop-fix-jp", "ct-air-jp", "ct-flex-and-flash-builder-jp", "ct-incopy-jp", "ct-japan-lounge-jp", "ct-illustrator-draw-jp"} as list
set ocidCategoryArray to refMe's NSArray's arrayWithArray:(listCategoryIDJp)
set ocidCategoryM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidCategoryM's setArray:(ocidCategoryArray)
set ocidSortedArray to ocidCategoryM's sortedArrayUsingSelector:("localizedCompare:")
set listCategoryIDJp to ocidSortedArray as list


############################################
##保存先
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
##保存ファイルパス
set ocidNewFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSaveFileName)

############################################
##XML
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"opml"
###【A-1】ROOT エレメントにネームスペース
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0"))
###【A-B】子要素
set ocidHeadElement to (refMe's NSXMLElement's alloc()'s initWithName:("head"))
###【A-B-1】子要素
set ocidTitleElement to (refMe's NSXMLElement's elementWithName:("title"))
(ocidTitleElement's setStringValue:(strTitle))
##子要素titleエレメント をheadにセット
(ocidHeadElement's addChild:(ocidTitleElement))
##↑で追加したheadエレメントをROOTにセット
(ocidRootElement's addChild:(ocidHeadElement))

###【A-C-1】子要素
set ocidBodyElement to (refMe's NSXMLElement's alloc()'s initWithName:("body"))
##【A-C-2】bodyエレメントの外側のoutline=フォルダ名になる
set ocidOutLineDivElement to (refMe's NSXMLElement's elementWithName:("outline"))
##外側のoutlineにネームスペース text とtitleを追加
ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:(strOutlineName))
ocidOutLineDivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:(strOutlineName))
##【A-C-D】内側のoutlineエレメントこれが本体

repeat with itemCategoryIDJp in listCategoryIDJp
  
  set ocidOutLineItemElement to (refMe's NSXMLElement's elementWithName:("outline"))
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("rss")))
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("text") stringValue:(itemCategoryIDJp)))
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemCategoryIDJp)))
  set strBaseURL to ("https://community.adobe.com/t5/" & itemCategoryIDJp & "/ct-p/" & itemCategoryIDJp & "") as text
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("htmlUrl") stringValue:(strBaseURL)))
  set strNewPostRssURL to ("https://community.adobe.com/havfw69955/rss/Category?category.id=" & itemCategoryIDJp & "&interaction.style=forum&feeds.replies=true") as text
(ocidOutLineItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xmlUrl") stringValue:(strNewPostRssURL)))
  ##内側アイテムoutlineエレメントを 外側のoutlineエレメントにセットしていく
(ocidOutLineDivElement's addChild:(ocidOutLineItemElement))
end repeat

#####外側のoutlineエレメントをbodyエレメントに追加
(ocidBodyElement's addChild:(ocidOutLineDivElement))
###bodyエレメントをROOTにセット
(ocidRootElement's addChild:(ocidBodyElement))
###【XML】↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントにする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidNewFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)



|

[OPML]値の取得と表示(feedly.comのエキスポートしたOPML)


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

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

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

#############################
###ダイアログ
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 appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
############UTIリスト
set listUTI to {"public.xml", "dyn.ah62d4rv4ge8086drru", "public.opml"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
on error
  log "エラーしました"
return "エラーしました"
end try

########################################
##本処理
repeat with itemAliasFilePath in listAliasFilePath
  ###入力パス
  set strFilePath to (POSIX path of itemAliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  ###ファイル読み込み
  set ocidOption to (refMe's NSXMLDocumentTidyXML)
  set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference))
  ###XMLドキュメント
  set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
  ###ROOTエレメント
  set ocidRootElement to ocidReadXMLDoc's rootElement()
  set ocidHeadArray to (ocidRootElement's elementsForName:("head"))
  set listEntryArray to (ocidRootElement's nodesForXPath:("//head/title") |error|:(reference))
  set strTitle to (item 1 of listEntryArray)'s stringValue as text
  log strTitle
  ###bodyエレメント
  set ocidBody to (ocidRootElement's elementsForName:("body"))'s firstObject()
  ###outlineエレメント
  set ocidOutLineArray to (ocidBody's elementsForName:("outline"))
  repeat with itemOutLineArray in ocidOutLineArray
    set ocidTextAttr to (itemOutLineArray's attributeForName:("text"))
    if ocidTextAttr is not (missing value) then
      log ocidTextAttr's stringValue as text
    end if
    set ocidTitleAttr to (itemOutLineArray's attributeForName:("title"))
    if ocidTitleAttr is not (missing value) then
      log ocidTitleAttr's stringValue as text
    end if
    ###outlineエレメントの子要素
    set ocidContentsArray to (itemOutLineArray's elementsForName:("outline"))
    repeat with itemContentsArray in ocidContentsArray
      set ocidContTextAttr to (itemContentsArray's attributeForName:("text"))
      set ocidContTypeAttr to (itemContentsArray's attributeForName:("type"))
      set ocidContTitleAttr to (itemContentsArray's attributeForName:("title"))
      set ocidContXmlUrlAttr to (itemContentsArray's attributeForName:("xmlUrl"))
      set ocidContHtmlUrlAttr to (itemContentsArray's attributeForName:("htmlUrl"))
      if ocidContTextAttr is not (missing value) then
log ocidContTextAttr's stringValue as text
      end if
      if ocidContTypeAttr is not (missing value) then
log ocidContTypeAttr's stringValue as text
      end if
      if ocidContTitleAttr is not (missing value) then
log ocidContTitleAttr's stringValue as text
      end if
      if ocidContXmlUrlAttr is not (missing value) then
log ocidContXmlUrlAttr's stringValue as text
      end if
      if ocidContHtmlUrlAttr is not (missing value) then
log ocidContHtmlUrlAttr's stringValue as text
      end if
    end repeat
  end repeat
  
end repeat




|

その他のカテゴリー

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