Skip to content

Commit

Permalink
Path Rename: return target without newline
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgalvao committed Nov 14, 2024
1 parent aad4168 commit cc74964
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"inputType" : 1,
"outputDescription" : "File path of the rename",
"outputType" : 1,
"script" : "function envVar(varName) {\n return $.NSProcessInfo\n .processInfo\n .environment\n .objectForKey(varName).js\n}\n\nfunction isDir(pathString) {\n return $.NSFileManager.defaultManager\n .attributesOfItemAtPathError(pathString, undefined)\n .js[\"NSFileType\"].js === \"NSFileTypeDirectory\"\n}\n\nfunction isPackage(pathString) {\n return $.NSURL.fileURLWithPath(pathString)\n .resourceValuesForKeysError([$.NSURLIsPackageKey.js], undefined)\n .js[\"NSURLIsPackageKey\"].js\n}\n\nfunction run(argv) {\n const sourcePath = argv[0]\n const sourcePathDir = $(sourcePath).stringByDeletingLastPathComponent.js\n const fileManager = $.NSFileManager.defaultManager\n const overwrite = envVar(\"overwrite\") === \"1\"\n const ignoreExtension = envVar(\"ignore_extension\") === \"1\"\n const sourceExtension = $(sourcePath).pathExtension.js\n const isFolder = isDir(sourcePath) && !isPackage(sourcePath)\n const extension = (sourceExtension.length === 0 || isFolder || ignoreExtension) ? \"\" : \".\" + sourceExtension\n const newName = envVar(\"new_name\") + extension\n const destinationPath = $(sourcePathDir).stringByAppendingPathComponent(newName).js\n\n if (fileManager.fileExistsAtPath(destinationPath)) {\n if (!overwrite) throw \"Path exists: \" + sourcePath\n fileManager.removeItemAtPathError(destinationPath, undefined)\n }\n\n fileManager.moveItemAtPathToPathError(sourcePath, destinationPath, undefined)\n return destinationPath\n}",
"script" : "function alfredArgs(args) {\n return JSON.stringify({ alfredworkflow: { arg: args } })\n}\n\nfunction envVar(varName) {\n return $.NSProcessInfo\n .processInfo\n .environment\n .objectForKey(varName).js\n}\n\nfunction writeSTDOUT(string) {\n const nsdata = $(string).dataUsingEncoding($.NSUTF8StringEncoding)\n $.NSFileHandle.fileHandleWithStandardOutput.writeData(nsdata)\n}\n\nfunction isDir(pathString) {\n return $.NSFileManager.defaultManager\n .attributesOfItemAtPathError(pathString, undefined)\n .js[\"NSFileType\"].js === \"NSFileTypeDirectory\"\n}\n\nfunction isPackage(pathString) {\n return $.NSURL.fileURLWithPath(pathString)\n .resourceValuesForKeysError([$.NSURLIsPackageKey.js], undefined)\n .js[\"NSURLIsPackageKey\"].js\n}\n\nfunction run(argv) {\n const sourcePath = argv[0]\n const sourcePathDir = $(sourcePath).stringByDeletingLastPathComponent.js\n const fileManager = $.NSFileManager.defaultManager\n const overwrite = envVar(\"overwrite\") === \"1\"\n const ignoreExtension = envVar(\"ignore_extension\") === \"1\"\n const sourceExtension = $(sourcePath).pathExtension.js\n const isFolder = isDir(sourcePath) && !isPackage(sourcePath)\n const extension = (sourceExtension.length === 0 || isFolder || ignoreExtension) ? \"\" : \".\" + sourceExtension\n const newName = envVar(\"new_name\") + extension\n const destinationPath = $(sourcePathDir).stringByAppendingPathComponent(newName).js\n\n if (fileManager.fileExistsAtPath(destinationPath)) {\n if (!overwrite) throw \"Path exists: \" + sourcePath\n fileManager.removeItemAtPathError(destinationPath, undefined)\n }\n\n fileManager.moveItemAtPathToPathError(sourcePath, destinationPath, undefined)\n return alfredArgs(destinationPath)\n}",
"scriptType" : 7,
"state" : 0,
"taskDescription" : "Change names of paths",
Expand Down

0 comments on commit cc74964

Please sign in to comment.