Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript error -1700 type item when open file

I am trying to write an AppleScript that will open my Bookmarks from Safari using TextEdit and then do a find and replace for domains that have changed. I have over 2000 of them.


I want to write the AppleScript where if someone else wants to use the same script they can. So I am trying to use variable for path. When I run the AppleScript I get error below.



do shell script "/usr/bin/plutil -convert xml1 ~/Library/Safari/Bookmarks.plist"


set userHome to (text of word -1 of (path to home folder as text))

tell application "Finder"

open (userHome & ":Library:Safari:Bookmarks.plist")

tell application "TextEdit" to activate

tell application "System Events" to tell process "TextEdit"


keystroke "f" usingcommand down & option down


keystroketabusingshift down

keystroke "Find this Text" & tab & "Replace with this Text"

delay 0.5

tell front window


clickbutton "All" of group 2 of scroll area 1

delay 0.5


clickbutton "Done" of scroll area 1

end tell

end tell

end tell


error "Finder got an error: Can’t make \"HD:Users:Username:Library:Safari:Bookmarks.plist\" into type item." number -1700 from "HD:Users:Username:Library:Safari:Bookmarks.plist" to item


AppleScript Safari-OTHER, OS X Mountain Lion (10.8.1)

Posted on Sep 4, 2012 1:51 PM

Reply
9 replies

Sep 4, 2012 2:52 PM in response to twtwtw

Here's how you work through the property list file in applescript, without GUI scripting. This version is set to work on top level items in the Bookmarks Menu, but is easily expandable to bookmark subfolders, the Reading List, the Bookmarks Bar, or even the History list.


property searchText : "textToFix"

property replaceText : "replacmentText"


if application "Safari" is running then

display alert "Please quit Safari before running this script" as critical

return

end if


tell application "System Events"

set bookmarkPlist to property list file "~/Library/Safari/Bookmarks copy.plist"

tell bookmarkPlist

tell property list item "Children"

set bookmarkMenu to first property list item whose property list item "Title"'s value is "BookmarksMenu"

tell bookmarkMenu

tell property list item "Children"

set itemsToRevise to every property list item whose property list item "URLString"'s value contains searchText

repeat with thisItem in itemsToRevise

tell thisItem

set value of property list item "URLString" to my swapStrings(property list item "URLString"'s value)

end tell

end repeat

end tell

end tell

end tell

end tell

end tell


on swapStrings(txt)

set {oldTID, my text item delimiters} to {my text item delimiters, searchText}

set bits to text items of txt

set my text item delimiters to replaceText

set newString to bits as text

set my text item delimiters to oldTID

return newString

end swapStrings

Applescript error -1700 type item when open file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.