I do not use the global shipping program, but this was an interesting puzzle.
Test Steps:
I enabled global shipping on several listings.
-
I added a new folder to my Downloads folder named “Export”, but you can name it whatever you wish.
-
I selected and exported these four listings, and several other listings with global shipping disabled, as a single file using the default name of “Exported listings.gslisting” to the “Export” folder.
-
When prompted by the AppleScript I select the “Exports” folder.
When prompted to enter text to find I pasted:
“usesGlobalShippingProgram”:1
When promoted to enter the replacement text I pasted:
“usesGlobalShippingProgram”:0
When the AppleScript completed its task it displayed a dialog with the following text:
Replacement complete!
4 JSON files processed.
-
I imported the “Exported listings.gslisting” file into GS and the global shipping was disabled on the four listings, remained disabled on the other listings, and no shipping details were changed.
The AppleScript targets JSON files within the exported file that you can examine in the Finder by selected the export file and then using the mouse’s contextual menu to select “Show Package Contents”. The individual JSON files can be opened in TextEdit.
-- AppleScript to recursively find all .json files in a folder and replace text inside them
-- Prompt user for the folder to process
set targetFolder to choose folder with prompt "Select the folder containing JSON files:"
-- Prompt for the text to find
display dialog "Enter the text to find:" default answer "" buttons {"Cancel", "OK"} default button "OK"
set findText to text returned of result
-- Prompt for the replacement text
display dialog "Enter the replacement text:" default answer "" buttons {"Cancel", "OK"} default button "OK"
set replaceText to text returned of result
-- Validate inputs
if findText is "" then
display alert "Find text cannot be empty." as warning
return
end if
-- Use 'find' to locate JSON files recursively
try
set jsonFileList to paragraphs of (do shell script "find " & quoted form of POSIX path of targetFolder & " -type f -name '*.json'")
on error
display alert "Error searching for JSON files." as warning
return
end try
if (count of jsonFileList) is 0 then
display alert "No JSON files found in the selected folder." as warning
return
end if
-- Loop through each JSON file and replace text
repeat with jsonFile in jsonFileList
try
-- Read file content
set fileContent to do shell script "cat " & quoted form of jsonFile
-- Replace text (using sed for speed and safety)
set escapedFind to my escapeForSed(findText)
set escapedReplace to my escapeForSed(replaceText)
do shell script "sed -i '' 's/" & escapedFind & "/" & escapedReplace & "/g' " & quoted form of jsonFile
on error errMsg
display alert "Error processing file: " & jsonFile & return & errMsg as warning
end try
end repeat
display alert "Replacement complete!" message ((count of jsonFileList) as text) & " JSON files processed."
-- Helper function to escape special characters for sed
on escapeForSed(theText)
set theText to my replaceTextInString(theText, "/", "\\/")
set theText to my replaceTextInString(theText, "&", "\\&")
return theText
end escapeForSed
-- Generic replace function
on replaceTextInString(theText, searchString, replacementString)
set AppleScript's text item delimiters to searchString
set tempList to every text item of theText
set AppleScript's text item delimiters to replacementString
set newText to tempList as text
set AppleScript's text item delimiters to ""
return newText
end replaceTextInString