Jump to content

Bulk addition of text with local links


Recommended Posts

Background

I often find that I end up doing things on my mac that only need doing two or three times a year - just long enough for me to forget what to do! So I got into the habit of writing notes with local links to the apps that I need to use - for example

Open Terminal then do....XYZ

[The text 'Terminal' has the link: file:///applications/terminal.app. I can tap it and open Terminal without breaking into a sweat].

1. Then I thought it would be easier to create a text document list of ALL my apps. in Terminal...

cd /applications

ls > applicationList.txt

Which gives my text list....

1Password.app

Acorn-5.app

Adobe Acrobat Reader DC.app

Alfred 3.app

Amazon Music.app

etc

2. ...then use BBEdit to fill the spaces in some of the app names...

# links don't like spaces

Find " "

Replace "%20"

 

Now I have

1Password.app

Acorn-5.app

Adobe%20Acrobat Reader DC.app

Alfred 3.app

Amazon Music.app

etc

 

3. ...and (also in BBEdit) append 'file:///'...

# append file address to each (partial) app path

Find "^"

Replace "file:///applications/"

 

...to all the app names...

 

This leaves me with...

file:///1Password.app

file:///Acorn-5.app

file:///Adobe%20Acrobat%20Reader%20DC.app

file:///Alfred%203.app

file:///Amazon%20Music.app

etc

4. before pasting into Evernote .The pasted text gives me the tappable local links that I want but they are ugly and big.

 

So here's the question: Is there a way for me to grep up the app names in BBEdit so that I can paste them all into Evernote in one go? So that I end up with e.g., the text '1Password' has the link 'file:///1Password.app'. 

Just for emphasis - I know this can be achieved by manually K/link editing each app name and putting the path in but I assume that there's some format for achieving this in a single line. 

 

 

 

Link to comment
  • Level 5*
31 minutes ago, Jasp said:

So here's the question: Is there a way for me to grep up the app names in BBEdit so that I can paste them all into Evernote in one go? So that I end up with e.g., the text '1Password' has the link 'file:///1Password.app'. 

How do you feel about using Applescript on a Mac.
This  is simple html code that scripting can format and insert into a note.

And thanks for the concept.  I have a daily requirement for jumping to apps (daily journal) and the links will come in handy.

Link to comment
  • Level 5*
17 hours ago, Jasp said:

I'm not great with Applescript but can usually follow/adapt other peoples, if that's an offer DTLow!

I accept the challenge; I'll post back in a couple of hours.  If you get @JMichaelTX interested you'll get a second opinion on the code.

<edit>

Here's my script

  1. Code is used to retrieve the apps list (set theApps to (list folder (choose folder) without invisibles)
  2. The HTML code is formatted (set theHTML to "<div><a href=\"file:///a...)
    A handler/subroutine (APPHTML) is used to replace spaces with %20.  tbd <> characters
  3. The text is inserted into the currently selected note (set theNote to item 1 of (get selection))
                                                                                               (set HTML content of theNote to theHTML)

set theApps to (list folder (choose folder) without invisibles)
set theHTML to ""
repeat with
theApp in theApps
         
if length of theApp > 4 and text -4 thru -1 of theApp = ".app" then
             
set theHTML to theHTML & "<div><a href=\"file:///applications/" & my APPHTML(theApp) & "\">" & text 1 thru -5 of theApp & "</a></div>"
        
end if
 end repeat

tell application "Evernote"
     
set theNote to item 1 of (get selection)
     set HTML content of theNote to theHTML
end tell

 

 

on APPHTML(theApp) -- Replace spaces with %20
     
set theAppHTML to ""
     
set theAppChars to every character of theApp
     
repeat with theAppChar in theAppChars
          
if theAppChar as text = " " then set theAppChar to "%20"
          
set theAppHTML to theAppHTML & theAppChar
     
end repeat
     return theAppHTML
end APPHTML

Link to comment
  • Level 5*
22 hours ago, DTLow said:

 If you get @JMichaelTX interested you'll get a second opinion on the code.

<edit>

Here's my script

@DTLow, your script looks fine to me.  The only suggestion I have is to ask user for permission to overwrite the Note:

tell application "Evernote"
  set theNote to item 1 of (get selection)
  
  --- Get User's Permission to Overwrite Note ---  ##JMTX Add
  
  set noteTitle to title of theNote
  display dialog "Do you want to replace this Note with the App Link List?: " & return & noteTitle ¬
    with title ¬
    "Add HyperLinks to All Apps in Evernote Note" with icon stop
  
  set HTML content of theNote to theHTML
end tell

 

Link to comment

Thank you so much for trying to help me out here...I'm afraid I'm missing something. I'm not sure if I'm not doing what I should be with your script or if there's something funny about my MBP's set up. I have:

1. Amalgamated your suggestions like this VVV (and attached). The files compiles and runs. √

#
# DTlow script to change list of form '1Password.app'
# to 'file:///1password.app' but display'1Password.app'
# for use in e-notes to link to specfic apps to speed up
# multi-app, step-b-step instructions, etc. 
#
# https://discussion.evernote.com/topic/118491-bulk-addition-of-text-with-local-links/
#
set theApps to (list folder (choose folder) without invisibles)
set theHTML to ""
repeat with theApp in theApps
	if length of theApp > 4 and text -4 thru -1 of theApp = ".app" then
		set theHTML to theHTML & "<div><a href=\"file:///applications/" & my APPHTML(theApp) & "\">" & text 1 thru -5 of theApp & "</a></div>"
	end if
end repeat

tell application "Evernote"
	set theNote to item 1 of (get selection)
	
	--- Get User's Permission to Overwrite Note ---  ##JMTX Add
	
	set noteTitle to title of theNote
	display dialog "Do you want to replace this Note with the App Link List?: " & return & noteTitle ¬
		with title ¬
		"Add HyperLinks to All Apps in Evernote Note" with icon stop
	
	set HTML content of theNote to theHTML
end tell

on APPHTML(theApp) -- Replace spaces with %20
	set theAppHTML to ""
	set theAppChars to every character of theApp
	repeat with theAppChar in theAppChars
		if theAppChar as text = " " then set theAppChar to "%20"
		set theAppHTML to theAppHTML & theAppChar
	end repeat
	return theAppHTML
end APPHTML

2. I get to select the file (.txt file created in TextEdit, attached below) I'm prompted to pick a file but it's gray and can't be selected. It doesn't seem to be peculiar to .txt files (they're all gray). And if I use alternative Applescript ...

tell application "Finder"
	files of folder (choose folder) -- Finder file objects
	name of files of folder (choose folder) -- names of files
end tell

or just the first line of your code...

set theApps to (list folder (choose folder) without invisibles)

...there's no change: grayness.

Do you have any idea what I'm getting wrong please?

 

DTLow-test.scpt

applicationList2.txt

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...