Xcode 14.2 and linking to a specific file

Hello there :wave:

Probably I’m doing something wrong, but the Hook app doesn’t want link to a specific file in Xcode workspaces, tho it can link to workspaces in general

The Xcode version version 14.2 (14C18)
The Hook app version 4.0.1 (5010) / Scripts Version 253

I use default Xcode scripts :bowing_man:

Welcome to the Hookmark Forum , @elfenlaid. Thanks for asking about that.

Are you seeing No linkable item found in Xcode? This has some answers:

Does that help?

Thanks for the quick reply and kind words

I see that Hook figures out the active Xcode’s workspace, but no the opened file. The link leads to the workspace. I wonder maybe there’s something I’m missing :thinking:

Sorry for the trouble.

Could you please restart Hookmark and see if the problem goes away?

Thank you

No worries, I’ve restarted the app and the machine, but the problem is still there :cry:

I forgot to mention that I also on macOS 13.2 (22D49), maybe that could be a potential problem :thinking:

Could you please run the following script in /Applications/Utilities/Script Editor and post the info in the dialog boxes?

Script
tell application "Xcode"
	set projectName to name of active scheme of active workspace document
	set prefixName to projectName & " — "
	set activeWindowName to name of window 1
	display dialog "activeWindowName: " & activeWindowName
	
	set activeDocumentName to (characters ((count of prefixName) + 1) thru -1 of (activeWindowName)) as text
	display dialog "activeDocumentName: " & activeDocumentName
	set current_name to activeDocumentName
	if length of current_name is greater than 9 then
		if text -8 through -1 of current_name is equal to "— Edited" then
			set current_name to text 1 through -10 of current_name
		end if
	end if
	display dialog "current_name: " & current_name
	
	repeat with source_doc in documents
		if current_name is equal to name of source_doc then
			return "file://" & path of source_doc
		end if
	end repeat
	get "file://" & path of active workspace document
	
end tell

Also , just want to be sure, if you go to Hookmark Preferences window → Script->Xcode, there is no * at the end of Xcode?

Thank you

Yeap, I confirm I don’t have the star there

I’ve run the script and the result depends on Xcode projects type. The script works flawlessly in projects without workspaces. I’m attaching a sample project to try it out Dropbox - SampleApp.zip - Simplify your life, but I think any project with a workspace would work

So, here are the script’s output when I open the SampleApp.xcodeproj:

activeWindowName: SampleApp — ContentView.swift
activeDocumentName: ContentView.swift
current_name: ContentView.swift
"file:///Users/elfenlaid/Desktop/SampleApp/SampleApp/ContentView.swift"

Also, the Hook app works flawlessly with such project types :raised_hands:

But if I run the script in opened SampleWorkspace.xcworkspace, I get the following output:

activeWindowName: SampleWorkspace — SampleAppApp.swift
activeDocumentName: ace — SampleAppApp.swift
current_name: ace — SampleAppApp.swift
"file:///Users/elfenlaid/Desktop/SampleApp/SampleWorkspace.xcworkspace"

Thank you for the detailed information! That’s very helpful.

Here is the revised script. Could you please run it in Script Editor and see if it works for both Xcode project and workspace?

Script
tell application "Xcode"
	set activeDocumentName to (word -1 of (get name of window 1))
	set current_name to activeDocumentName
	if length of current_name is greater than 9 then
		if text -8 through -1 of current_name is equal to "— Edited" then
			set current_name to text 1 through -10 of current_name
		end if
	end if
	repeat with source_doc in documents
		if current_name is equal to name of source_doc then
			return "file://" & path of source_doc
		end if
	end repeat
	get "file://" & path of active workspace document
	
end tell

Thank you

Whoa, it works :raised_hands:

Many thanks for following it up

I’ve checked the script with workspaces, stand alone projects, and Swift Package Manager projects. Works like magic everywhere :sparkles:

Thank you for your feedback and help us debug!

I just updated the script server. Please go to Hookmark Preferences window → Update->Check now to update the script. If you don’t want to update to Hookmark 5, please click on “Remind me later” button in Software update window. The script will be updated anyway, version number 255.

Thank you

2 Likes

Can confirm that scripts 255 works as expected :raised_hands:

Many thanks!

I have a small side question. I’m using Hook through Setapp and it seems that on Setapp Hook is on version 4, right?

I’m not against buying a separate Hook license. It’s a great tool with a premium support :sweat_smile: Just wondering whether it makes sense to install Hook as a separate program or continue using Setapp installer?

I’m glad that worked. We have submitted Hookmark 5.0.1 for review at Setapp. It normally takes a week for review.

1 Like