Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

simple applescript string issue

Posted on 2008-11-10
3
Medium Priority
?
2,840 Views
Last Modified: 2012-06-21
This script works great.

But I would like to hard code in the following strings:

=====================
sSearch  

and

sReplace
=====================

I am not in a position to learn new code languages, so I figure this is a simple syntax issue.

The code asks for a pop up box currently:

// Snippet from the attached code //

      

    set sSearch to text returned of
     (display dialog "Enter the beginning of the path to be replaced:
(e.g. Macintosh HD:FolderName:)" default answer "")

      set sReplace to text returned of
    (display dialog "Edit this path to match how it should be edited for Items in the catalog:" default answer sSearch)


// End Snippet //

I just want to hard code sSearch to:

this exact string
----------------------------

C:\Documents and Settings\cntmedia\My Documents\cntmedia_library\Source\

----------------------------

And sReplace to the exact string:
----------------------------

/Volumes/300gig/cntmedia_library/Source/

----------------------------


Thanks!


(*  Change Path Script for Portfolio 8.5  *)
 
 
-- Check to make sure Portfolio is running 
tell application "Finder" to set P_app to every process whose name contains "Portfolio"
if P_app is {} then
	display dialog ¬
		"Portfolio must be running for this script to operate." buttons {"OK"} default button {"OK"}
	return
end if
 
tell application "Portfolio"
	-- Check to make sure a catalog is opened 
	tell application "Portfolio" to set windowCount to count every document
	if not (exists of document 1) then
		display dialog ¬
			"A Portfolio catalog must be opened for this script to operate." buttons {"OK"} default button {"OK"}
		return
	end if
	
	--Get the appropriate search information from the user
	set sSearch to text returned of (display dialog "Enter the beginning of the path to be replaced:
(e.g. Macintosh HD:FolderName:)" default answer "")
	set sReplace to text returned of (display dialog "Edit this path to match how it should be edited for Items in the catalog:" default answer sSearch)
	if name of selected gallery of the front document ` name of gallery 1 of the front document then
		set cButton to button returned of (display dialog "Edit items in the current gallery, or the whole catalog? " buttons {"Entire Catalog", "Current Gallery"} default button 1)
	else
		set cButton to "Entire Catalog"
	end if
	
	-- pad the strings with ":" at the end
	(*
	if the last character of sSearch ` ":" then set sSearch to sSearch & ":"
	if the last character of sReplace ` ":" then set sReplace to sReplace & ":"
	*)
	set searchLength to length of sSearch
	set replaceLength to length of sReplace
	
	-- go to the proper gallery
	if cButton = "Entire Catalog" then
		tell the front document to display gallery 1
	end if
	set currentGallery to name of selected gallery of the front document
	set recordCount to count every record of gallery currentGallery of the front document
	
	set myIndex to 1
	set replaceCount to 0
	tell gallery currentGallery of the front document
		repeat recordCount times
			if file path of record myIndex starts with sSearch then
				tell record myIndex
					set thePath to file path as Unicode text
					set recordLength to the length of thePath
					set file path to sReplace & characters (searchLength + 1) through (recordLength) of thePath
					set replaceCount to replaceCount + 1
				end tell
			end if
			set myIndex to myIndex + 1
		end repeat
	end tell
	
	-- If no items were found, tell the user and then quit.
	if replaceCount is 0 then
		display dialog ¬
			"No Item Paths were found to match the Path entered. 
			
Be sure you are entering the beginning of the path you want to edit (e.g. Macintosh HD:FolderName), not an item within the path  (e.g. FolderName)." with icon 2 buttons {"OK"} default button {"OK"}
		return
	else
		display dialog ¬
			"Script completed. " & replaceCount & " items edited. " & "
 
Items found with a matching file path have been edited." buttons {"OK"} default button {"OK"}
		
	end if
end tell

Open in new window

0
Comment
Question by:cntmedia
  • 2
3 Comments
 
LVL 7

Expert Comment

by:aherps
ID: 22927413

set sString to "C:\\Documents and Settings\\cntmedia\\My Documents\\cntmedia_library\\Source\\"
set sReplace to "/Volumes/300gig/cntmedia_library/Source/"

Open in new window

0
 

Author Comment

by:cntmedia
ID: 22936142
The script is returning an error of:


variable sSearch not Defined.

Wondering where I would be messing up there.

I understand it's doing a query and replace, but it didn't work on my side.
0
 
LVL 7

Accepted Solution

by:
aherps earned 2000 total points
ID: 22936954
Sorry - mistype.

If you're just trying to hard code the results (without the need for the prompt) see below.

Sorry, I had sString instead of sSearch
set sSearch to "C:\\Documents and Settings\\cntmedia\\My Documents\\cntmedia_library\\Source\\"
set sReplace to "/Volumes/300gig/cntmedia_library/Source/"

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question