Open specific invisible folder

When you regularly open the same invisible folder, typing its path every time gets tedious.
Here’s a little script that will open the folder for you.

set myFolder to "/path/to/folder/"

-- localise these two
set myGoButton to "Ga"-- button on sheet/window where path is entered
set myWindow to "Naar map gaan"-- title of window where path is entered

-- get frontmost app
tell application "System Events"
	set frontappName to name of first process whose frontmost is true
end tell

tell application "Finder"
	activate
	set the clipboard to myFolder
end tell

tell application "System Events" to tell process "Finder"
	set boolOpenSheet to (windows is not {})
	-- true: a window is already open, command opens a sheet on that window
	-- false: no open window, command opens one
	keystroke "g" using {command down, shift down} -- "go to folder"
	keystroke "v" using command down -- paste path
	
	if boolOpenSheet then -- close the sheet
		click button myGoButton of sheet 1 of front window
	else -- close the window
		click button myGoButton of window myWindow
	end if
end tell

-- return to frontmost app
tell application frontappName to activate
tell application "Finder"
	reopen
	activate
	set target of Finder window 1 to POSIX file "/etc/apache2"
end tell

This method and GUI scripting the Go to Folder… window seem to act mostly the same way. Both expand aliases / symlinks and ignore sidebar locations in column view.

Well I think, and maybe others too, that for every hidden file/folder you need to create another script. I have this script and created a short-key to launch it to toggle between showing invisible files in the Finder.

if not showAllFiles() then
	setShowAllFiles("TRUE")
else
	setShowAllFiles("FALSE")
end if

tell application "Finder" to quit

set processList to getProcessList()
repeat until "Finder" is not in processList
	set processList to getProcessList()
end repeat

tell application "Finder" to launch

on showAllFiles()
	try
		return (do shell script "defaults read com.apple.finder AppleShowAllFiles") as boolean
	on error
		return false
	end try
end showAllFiles

on setShowAllFiles(__state)
	do shell script "defaults write com.apple.finder AppleShowAllFiles " & __state
end setShowAllFiles

on getProcessList()
	tell application "System Events" to return the name of every process
end getProcessList