IntelliJ Goland or IntelliJ IDEA

I tried to integrate Goland with Hook and found that the current IntelliJ IDEA integration is not ideal.

Current Goland/IDEA supports internal jetbrains:// links to project, file in the project, and cursor position.

I created a script for creating a link and getting a nice name.

Get link

This script creates a link to the whole project because the link to the cursor position or file is pretty unuseful. It can be easily updated to get a link to file instead.

Preparation

You need to setup a keyboard shortcut for ā€œCopy pathā€¦Toolbox URLā€ from keymap settings. In my case its āŒƒā‡§āŒ„āŒ˜+Š”, if you choose differently ā€” youā€™ll need to update the script.

Also, for IDEA/rubymine/pycharm users - you need to update application id from com.jetbrains.goland to id of your app. You can find this ID by passing to console osascript -e 'id of app "Goland"'

Script

set the clipboard to ""
tell application id "com.jetbrains.goland"
	activate
end tell

tell application "System Events"
	keystroke "c" using {shift down, command down, option down, control down}
	delay 0.1
	set fp to the clipboard
end tell

set AppleScript's text item delimiters to ":"
set theTextItems to every text item of fp
set result to (text items 1 thru ((length of theTextItems) - 2) of theTextItems as string)
get result

Get pretty name

The same thing, donā€™t forget about the custom shortcut.

set the clipboard to ""
tell application id "com.jetbrains.goland"
	activate
end tell

tell application "System Events"
	keystroke "c" using {shift down, command down, option down, control down}
	delay 0.1
	set fp to the clipboard
end tell

set AppleScript's text item delimiters to "project="
set parsePjName1 to text item 2 of (every text item of fp)
set AppleScript's text item delimiters to "&"
set result to text items 1 thru ((length of every text item of parsePjName1) - 1) of parsePjName1
get result as string

I assume that the first script may need to be updated to create a link based on project name, but on another side, some of you may want to have a link to the specific file, instead of the link to the project, so I decided to leave the first version of the script as more hackable option.

I wrote updated script for idea (no need to add ā€œGet nameā€ script, just add to ā€œGet Addressā€, also, no need to assign custom shortcut)
Iā€™m pretty sure it can be used as standard IDEA script, btw
But, intellij toolbox need to be installed for opening created links

set the clipboard to ""
tell application id "com.jetbrains.intellij"
	activate
end tell

tell application "System Events"
	key code 56
	key code 56
	delay 0.2
	keystroke "toolbox URL"
	delay 0.4
	key down return
	delay 0.2
	set fp to the clipboard
end tell


set AppleScript's text item delimiters to "&"
set parsePjLink to text item 1 of (every text item of fp)

set AppleScript's text item delimiters to "project="
set parsePjName1 to text item 2 of (every text item of fp)
set AppleScript's text item delimiters to "&"
set result to text items 1 thru ((length of every text item of parsePjName1) - 1) of parsePjName1
get result as string
set the fullink to "[" & result & "](" & parsePjLink as string & ")"
get fullink

wdyt?

Iā€™m using InjelliJ IDEA 2022.1 and hook. Iā€™ve noticed that I can get a hook link to a Java source file once or twice, but after that Hook seems to lock up. Itā€™s fine again if I restart hook but again I can only use it once or twice.

Anyone else having this?

I just tried it and it seems to be working fine. When you say lock up, do you mean it hangs? Does it lock up for other apps? Could you please post a screenshot here?

Hi, thereā€™s nothing to show Iā€™m afraid. The hook app itself simply stops responding to anything - CTRL+H or clicking on the app in the menu bar. I have to kill it with the process manager and then restart it. This is something that only seems to happen with IntelliJ, every other app I hook is working absolutely fine. And as I said, itā€™s only after one or two hook-ings (is that a verb) that the problem occurs. Very odd.

BTW: Iā€™m using the default scripts, I havenā€™t modified them in any way.

I am not sure if this is too much trouble for you. When lock-up happens, could you please open Activity Monitor, double click on Hook process, a small window with Hook process info will show. Then click on ā€œSampleā€ button, wait until sample is taken, save the sample file and send it to support@cogsciapps.com.

Also, are you running an clipboard manager?

Thank you

No problem at all - just sent the sample.

Re clipboard managers:

I run Alfred but with clipboard features disabled (as far as I can tell) and PopClip.

However Iā€™ve just quit both of those and the problem still occurs.

Iā€™m actually on my personal M1 Mac Pro right and can reproduce the issue which I first saw on my work Intel Mac Pro. This time (on my M1) it eventually recovered with the message:

Thank you for the info.

First, could you please turn off ā€œShow current itemā€™s number of hooks in menu bar iconā€ and see if it make any difference? Just go to Hook Preferences window ā†’ General, check off ā€œShow current itemā€™s number of hooks in menu bar iconā€ checkbox.

If the problem persists, could you please replace the script in Hook Preferences window ā†’ Scripts->IntelliJ IDEA->Get Address with the following script, click on save button and see if it make any difference?

Summary
display dialog "test"

set the clipboard to ""
tell application id "com.jetbrains.intellij"
	activate
end tell

delay 0.5

tell application "System Events"
	keystroke "c" using {shift down, command down}
	delay 0.1
	repeat 10 times -- poll clipboard for ~2.5 seconds. Sometimes set x to the clipboard throws exception
		try
			set fp to the clipboard
			if fp is not equal to "" then
				exit repeat
			end if
		end try
		delay 0.1
	end repeat
	
end tell
get fp

After the test is done, please click on ā€œReset to defaultā€ button too remove the changes.

Regarding Safari issue, does it only happen once or it is a persistent problem?

I had to add a ā€œ.ceā€ to the app id since at home I realised Iā€™m using the community edition there. I also had to comment out the display dialog ā€œtestā€ since that seemed to stop the hook window from appearing.

I also tried with ā€œShow current itemā€™s number of hooks in menu bar iconā€ off but that didnā€™t help.

BUT the extra ā€œdelay 0.5ā€ seems to make all the difference. Just adding that to the default script has made it rock solid, even with ā€œShow current itemā€™s numberā€¦" enabled.

With that added I havenā€™t been able to get it to fail!

Maybe itā€™s just that IntelliJ is a huge lethargic 3 legged comatose sloth of an application that needs extra time to get its bedroom slippers onā€¦

1 Like

I am so glad it works. You are awesome!

We will update the script.

2 Likes

Thank you - but you wrote the fixed script!

1 Like

I know this topic is old, but I tried to use Hookmark on my PhpStorm IDE, but didnā€™t work. I donā€™t understand it, because all Jetbrains IDEs have the possibility to bookmark all kind of resources (jetbrains://). So I thought this should work automaticly.
Has somebody an idea, what to do?