Handy Hint for Man Pages

Have a look at post #4. and see if that gives you the “tight” conversions you want.
I do not think you will have much luck trying to get preview to work for you, as you have discovered is not scriptable and does not have a library.

EDIT here is an example.

tell application "Finder"
	set target_path to ((path to desktop folder as Unicode text) as alias)
	set source_item to (choose file)
	set source_itemP to POSIX path of source_item
	set file_name to displayed name of source_item -- get displayed name
	set oldDelims to AppleScript's text item delimiters -- get normal dilm
	set AppleScript's text item delimiters to {"."} --sets new dilm
	set file_name to text item 1 of file_name -- get thye name of file without extension
	set AppleScript's text item delimiters to oldDelims -- resets dilm
	set target_pathP to POSIX path of target_path & file_name & ".pdf" as string
end tell
do shell script (" /usr/bin/pstopdf " & quoted form of source_itemP & " -o " & quoted form of target_pathP)

Mark Hunte,

Thanks for the quick reply.

I’m not a proficient scripter, how exactly would I adapt the script at Post #4?

I did an edit to my post. Did you see it?

Pardon I wasn’t sure that was meant for me.

I read it but can’t follow what it is doing. Probably because of my lack of familiarity with scripting and total ignorance of shell scripts.

I compiled it anyway and tried it.

It asks me to find an individual file, which I did and then it doesn’t ask me for a destination. It just seems to do nothing and closes. What am I missing?

Sorry to trouble you.

btw If I could automate this, I have found a manual way to do the job:

Open dialog in Preview
Navigate to folder full of eps files
Select all in folder
All files open and are converted to pdfs automatically
Close all open windows [cmd-opt-W]
save (twice) for each dialog that comes up [waiting for each dialog to appear - being OSX it doesn’t let me key ahead]
…till no windows are open

It drops all pdf files back into the originating folder

Next step would working out how to get it to step through a series of subfolders doing the same thing.

Thanks for your time and trouble.

The example should have put a pdf file on you desktop named the same as the file but as a pdf file and with a pdf extension.

putting it into an Automator script should not be that hard.

But there is no point me trying it for you unless the file the script creates is what you want.
have a look on the desktop for the file.

Ah thanks very much, I found it (I missed the bit about the desktop) and yes it is a perfectly OK pdf file.

Could you walk me through how you got it to do that please? I gather all the first bit is just getting the location and name of the file.

Is this the conversion bit?:

Wow it is terse!

;))

Now how do i get this into my automator workflow? I built one with everything including custom icon preview. This is the missing bit.

Thanks again. This is brilliant!

Actually It only took 5mins to write the automator action.
I will post it on one of my pages. As I do not think I can post here. But will walk you through here also.

Ok here is how to build the automator action.

In Automator.

From the FINDER actions.

choose the following action and set it as below -Ask for Finder items-

type : Folders
Start at : where ever you want
Prompt : Choose a Folder:

allow multiple Selections (un ticked)

From the FINDER actions.
choose the following action and set it as below -Get Folder Contents-
Repeat for each Subfolder found(ticked)


from the AUTOMATOR actions.

choose the following action and Run Applescript Replace the script in the applescript window with this code.

on run {input, parameters}
	tell application "Finder"
		repeat with i from 1 to number of items of input
			set source_item to item i of input
			
			set source_itemP to POSIX path of source_item
			do shell script (" /usr/bin/pstopdf " & quoted form of source_itemP)
		end repeat
		
	end tell
end run

*** EDIT ****
You are correct in regards to

		do shell script (" /usr/bin/pstopdf " & quoted form of source_itemP & " -o " & quoted form of target_pathP)

being the conversion line.
And Actually I just change the above script since you want the files to be created in the original folder.
The last part of the line which name the pdf file and path is not needed.

This is what its actually doing.
do shell script " /usr/bin/pstopdf ‘/Users/username/Desktop/Photo-5.eps’ "

/usr/bin/pstopdf is shell command that does the conversion.
‘/Users/username/Desktop/Photo-5.eps’ is the unix path to the source file .
the pdf if is created in the same folder as the original if no destination of name is given.

Thanks I’d appreciate a link.

I don’t know if you can fix Apple’s automator actions. The one for Preview’s file conversions should ideally just be extended to do the ps to pdf conversion, then it would be an all in one for graphic designers.

:slight_smile:

Good, you edited you post while I was on the phone.

I’ll set on creating and testing the Automator workflow now using your instructions.

Thanks a million.

Would it be possible to simply insert the pstopdf in the Preview file conversion drop down menu? That would be by far the tidiest solution.

The actual name of the action is : “Change Type of Images”

It’s into its 3rd nested folder so I guess it seems to be working fine. Although no thumbnails yet that I can discern.

Wow my first useful Automator workflow!

Thanks so much.

Mark where do I email the case of homebrew? :slight_smile:

I am working on polishing the workflow.

  1. It stopped 2/3rds way through the 8th folder of 246. Is it possible that my actions in OSX can interrupt the Automator workflow?

  2. I would like to get it to beep or read an announcement at the end of the conversion

  3. The closest I have got to that is “Ask for Confirmation” throwing up “The conversion is complete, would you like to choose another folder” - Cancel/OK

  4. Finder doesn’t read out the prompt it just tells me Automator wants my attention.

  5. I would like the workflow to loop at this point when I click OK and send me back to step one “Ask for Finder Item”

  6. I tried putting a copy of the workflow at this point, because I can’t see how to loop, but it rejects it as not an action/workflow. Is that because I saved it as an application?

I can’t set the path to save PDF files to a folder on my desktop
I set this do shell script " /usr/bin/pstopdf ‘/Users/myuser/Desktop/PDF’ "
but I get an error
/usr/bin/pstopdf failed on file /Users/myuser/PDF with error code -30998 (352956576)

Thanks

I saw this excellent post and I couldn’t resist having meddled a bit with some systems command lately.
My version uses the the index for the command line utilities right from my hd.
I prefer this one because I generally like to see all of them. I also prefer the browser because of the hyperlinks in the reference section. However this won’t get the highlighted colors one could get with an ansi terminal.
I saved this as an applet and an alias now resides among my predefined searches.

If you don’t have the Developer tools or reference documentation installed this
line should perform equally well as long as speed is not concerned.

on run
	set theCommand to ""
	tell application "System Events"
		
		set target_app to item 1 of (get name of processes whose frontmost is true)
		
	end tell
	tell application target_app
		repeat while theCommand is ""
			display dialog "View man page for this command:" default answer theCommand
			set theCommand to text returned of result
		end repeat
		
	end tell
	tell application "Safari" to open "Macintosh HD:Developer:Mac OS X Reference Library:documentation:Darwin:Reference:ManPages:index.html"
	-- 	tell application "Safari" to open location "http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/index.html"
	tell application "Safari" to activate
	delay 2
	tell application "System Events"
		key down command
		keystroke "f"
		key up command
		keystroke theCommand & "("
	end tell
	
end run

I am in Terminal a lot so I use this. Found it on MacOSXHints a while back.

I put it in my ~/.bash_login file and call it like this.

I’m using this, it takes the argument (syntax man something) from the address field in Safari and is triggered by a shortcut (via QuicKeys).
It opens the appropriate page on manpagez.com
The advantage of reading the man page online is that all cross-references are working


activate application "Safari"
tell application "System Events"
	tell process "Safari"
		set searchString to value of text field 1 of splitter group 1 of group 2 of tool bar 1 of window 1
	end tell
end tell
set {TID, text item delimiters} to {text item delimiters, space}
try
	set {cmd, arg} to {text item 1, text item 2} of searchString
	set text item delimiters to TID
on error
	set text item delimiters to TID
	return
end try
if cmd does not start with "man" then return

set foundURL to createManPageURL(arg)
if foundURL is missing value then return
try
	tell application "Safari"
		if text of document 1 is "" then
			set URL of document 1 to foundURL
		else
			tell window 1 to set current tab to (make new tab with properties {URL:foundURL})
		end if
	end tell
on error
	return
end try

on createManPageURL(topic)
	set section to word 2 of (do shell script "man " & topic)
	return "http://www.manpagez.com/man/" & section & "/" & topic & "/"
end createManPageURL

Thanks alot for sharing your code both of you.
The only thing I regret with reading in html is that I can’t get the keywords in color as I did in terminal. I’ll post the method for doing that when I have dissected the old PowerBook.

As for now I think I’ll lend some code of stefan and rework my solution so that I use the Address Bar of Safari with
Stefans way, but My own way as a backup when I miss spell the command.

I need a third way as well and that is when the Manual Page are coming from a Macport or other installation.

I let all My custom installations of Darwin binaries reside in /usr/local/opt by the way, and anything “that can be used” for a manual file in the /usr/local/man/man* directories. I’ll implement a manOnDisk command for those.

But not today. But I must say I’m playing with the thought of making a “Webpage Helper” and use it by url and get all output into a Safari Window cross references or not.

I must tell you about visor which is a free download from binaryages.com which lets you have a terminal window in the upper left corner of your screen just by hitting ctrl ctrl ! Its here: http://www.binaryage.com/#visor

Best Regards

McUsr

It amazes me that this thread is still active nearly 5 years after the my original post.

I have been using Visor for around a year now and absolutely love it! I especially like switching between tabs using {shift, command} right and left arrow.

I use DTerm for the same purpose. It attaches a terminal to the frontmost application as a drop down sheet.

I stopped using these script a while back.

I now use Bwana from Bruji.

And Just call it from a Hotkey app with

tell application "Bwana" to activate

A little Bwana man search window opens and becomes frontmost.
I just enter my command and hit search.
And the man page is displayed in safari.

I prefer this as it is very simple and I can use the safari inline search to find text I am looking for.